Question

 static inline bool cfq_slice_used(struct cfq_queue *cfqq)
 {
         if (cfq_cfqq_slice_new(cfqq))
                 return false;

         if (time_before(jiffies, cfqq->slice_end))
                 return false;

         return true;
 }

I am looking at this code which is a complete fairness queue, which I found on http://lxr.free-electrons.com/source/block/cfq-iosched.c#L4570

There is this line of code if (cfq_cfqq_slice_new(cfqq)) which to me looks like a function call where I just pass a cfqq struct. However, that function cfq_cfqq_slice_new is not really declared, or I don't understand how it is declared when doing crtl+f

The search results yield:

WARN_ON(cfq_cfqq_slice_new(cfqq));
Other if statements checking the same thing, calling the same function.

So does anyone know what this code does or how it looks like?

Was it helpful?

Solution

cfq_cfqq_slice_new() is defined through a macro.

On line 441 you'll see

CFQ_CFQQ_FNS(slice_new);

Which invokes:

#define CFQ_CFQQ_FNS(name)                                              \
static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq)         \
{                                                                       \
        (cfqq)->flags |= (1 << CFQ_CFQQ_FLAG_##name);                   \
}                                                                       \
static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq)        \
{                                                                       \
        (cfqq)->flags &= ~(1 << CFQ_CFQQ_FLAG_##name);                  \
}                                                                       \
static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq)         \
{                                                                       \
        return ((cfqq)->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0;      \
}

resulting in:

static inline void cfq_mark_cfqq_slice_new(struct cfq_queue *cfqq) 
{                                                                  
        (cfqq)->flags |= (1 << CFQ_CFQQ_FLAG_slice_new);           
}                                                                  
static inline void cfq_clear_cfqq_slice_new(struct cfq_queue *cfqq)
{                                                                  
        (cfqq)->flags &= ~(1 << CFQ_CFQQ_FLAG_slice_new);             
}                                                                  
static inline int cfq_cfqq_slice_new(const struct cfq_queue *cfqq) 
{                                                                  
        return ((cfqq)->flags & (1 << CFQ_CFQQ_FLAG_slice_new)) != 0; 
}

A bit earlier in the code is a enum which declares:

CFQ_CFQQ_FLAG_slice_new,        /* no requests dispatched in slice */

So cfq_cfqq_slice_new() just returns whether or not the CFQ_CFQQ_FLAG_slice_new is set in the struct cfq_queue.flags member.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top