lkml.org 
[lkml]   [2010]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 20/43] workqueue: reimplement work flushing using linked works
    On 02/26, Tejun Heo wrote:
    >
    > +static void move_linked_works(struct work_struct *work, struct list_head *head,
    > + struct work_struct **nextp)
    > +{
    > ...
    > + work = list_entry(work->entry.prev, struct work_struct, entry);
    > + list_for_each_entry_safe_continue(work, n, NULL, entry) {

    list_for_each_entry_safe_from(work) ? It doesn't need to move this
    work back.

    > @@ -680,7 +734,27 @@ static int worker_thread(void *__worker)
    > if (kthread_should_stop())
    > break;
    >
    > - run_workqueue(worker);
    > + spin_lock_irq(&cwq->lock);
    > +
    > + while (!list_empty(&cwq->worklist)) {
    > + struct work_struct *work =
    > + list_first_entry(&cwq->worklist,
    > + struct work_struct, entry);
    > +
    > + if (likely(!(*work_data_bits(work) &
    > + WORK_STRUCT_LINKED))) {
    > + /* optimization path, not strictly necessary */
    > + process_one_work(worker, work);
    > + if (unlikely(!list_empty(&worker->scheduled)))
    > + process_scheduled_works(worker);
    > + } else {
    > + move_linked_works(work, &worker->scheduled,
    > + NULL);
    > + process_scheduled_works(worker);
    > + }
    > + }

    So. If the next pending work W doesn't have WORK_STRUCT_LINKED,
    it will be executed first, then we flush ->scheduled.

    But,

    > static void insert_wq_barrier(struct cpu_workqueue_struct *cwq,
    > - struct wq_barrier *barr, struct list_head *head)
    > + struct wq_barrier *barr,
    > + struct work_struct *target, struct worker *worker)
    > {
    > ...
    > + /*
    > + * If @target is currently being executed, schedule the
    > + * barrier to the worker; otherwise, put it after @target.
    > + */
    > + if (worker)
    > + head = worker->scheduled.next;

    this is the "target == current_work" case,

    > - insert_work(cwq, &barr->work, head, work_color_to_flags(WORK_NO_COLOR));
    > + insert_work(cwq, &barr->work, head,
    > + work_color_to_flags(WORK_NO_COLOR) | linked);
    > }

    and in this case we put this barrier at the head of ->scheduled list.

    This means, this barrier will run after that work W, not before it?


    Hmm. And what if there are no pending works but ->current_work == target ?
    Again, we add the barrier to ->scheduled, but in this case worker_thread()
    can't even notice ->scheduled is not empty because it only checks ->worklist?

    Well. most probably I just misread this code completely...


    insert_wq_barrier() also does:

    unsigned long *bits = work_data_bits(target);
    ...
    *bits |= WORK_STRUCT_LINKED;

    perhaps this needs atomic_long_set(), although I am not sure this really
    matters.

    Oleg.



    \
     
     \ /
      Last update: 2010-03-01 15:57    [W:4.967 / U:0.096 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site