Re: [REGRESSION] RLIMIT_DATA crashes named

From: Konstantin Khlebnikov
Date: Sat Sep 17 2016 - 17:40:49 EST


On Sat, Sep 17, 2016 at 3:20 PM, Cyrill Gorcunov <gorcunov@xxxxxxxxx> wrote:
> On Sat, Sep 17, 2016 at 03:09:09PM +0300, Konstantin Khlebnikov wrote:
>> >
>> > Seems I don't understand the bottom unlikely...
>>
>> This is gcc extrension: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
>> Here macro works as a function which returns bool
>
> no, no, I know for what unlikely extension stand for.
> it was just hard to obtain from without the context.
> this extension implies someone calls for
> if (printk_periodic()) right?

Yep.


Here is perfect macro for that jiffies check: time_in_range_open.

/*
* Calculate whether a is in the range of [b, c).
*/
#define time_in_range_open(a,b,c) \
(time_after_eq(a,b) && \
time_before(a,c))

So... better version looks like

#define printk_periodic(period, fmt, ...)
({
static unsigned long __prev __read_mostly = INITIAL_JIFFIES - (period);
unsigned long __now = jiffies;
bool __print = !time_in_range_open(__now, __prev, __prev + (period));

if (__print) {
__prev = __now;
printk(fmt, ##__VA_ARGS__);
}
unlikely(__print);
})

Attachment: printk-add-pr_warn_once_per_minute
Description: Binary data