On Tue, Nov 17, 2020 at 06:19:52PM -0500, Joel Fernandes (Google) wrote:
> +/* Per-task interface */
> +static unsigned long sched_core_alloc_task_cookie(void)
> +{
> +     struct sched_core_cookie *ptr =
> +             kmalloc(sizeof(struct sched_core_cookie), GFP_KERNEL);
> +
> +     if (!ptr)
> +             return 0;
> +     refcount_set(&ptr->refcnt, 1);
> +
> +     /*
> +      * NOTE: sched_core_put() is not done by put_task_cookie(). Instead, it
> +      * is done after the stopper runs.
> +      */
> +     sched_core_get();
> +     return (unsigned long)ptr;
> +}
> +
> +static bool sched_core_get_task_cookie(unsigned long cookie)
> +{
> +     struct sched_core_cookie *ptr = (struct sched_core_cookie *)cookie;
> +
> +     /*
> +      * NOTE: sched_core_put() is not done by put_task_cookie(). Instead, it
> +      * is done after the stopper runs.
> +      */
> +     sched_core_get();
> +     return refcount_inc_not_zero(&ptr->refcnt);
> +}
> +
> +static void sched_core_put_task_cookie(unsigned long cookie)
> +{
> +     struct sched_core_cookie *ptr = (struct sched_core_cookie *)cookie;
> +
> +     if (refcount_dec_and_test(&ptr->refcnt))
> +             kfree(ptr);
> +}

> +     /*
> +      * NOTE: sched_core_get() is done by sched_core_alloc_task_cookie() or
> +      *       sched_core_put_task_cookie(). However, sched_core_put() is done
> +      *       by this function *after* the stopper removes the tasks from the
> +      *       core queue, and not before. This is just to play it safe.
> +      */

So for no reason what so ever you've made the code more difficult?

Reply via email to