Re: [PATCH V5 4/7] jump_label: Sort entries of the same key by the code

From: Daniel Bristot de Oliveira
Date: Mon Apr 15 2019 - 07:34:00 EST


On 4/15/19 12:55 PM, Peter Zijlstra wrote:
> On Mon, Apr 01, 2019 at 10:58:16AM +0200, Daniel Bristot de Oliveira wrote:
>> In the batching mode, entries with the same key should also be sorted by the
>> code, enabling a bsearch() of a code/addr when updating a key.
>
> Might be good to explain *why*.
>
> We can see what the code does, explaining why we do things is what we
> have Changelogs for.

Ack! I will explain why,

>> Signed-off-by: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
>> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
>> Cc: Borislav Petkov <bp@xxxxxxxxx>
>> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
>> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
>> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
>> Cc: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>
>> Cc: Jiri Kosina <jkosina@xxxxxxx>
>> Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
>> Cc: "Peter Zijlstra (Intel)" <peterz@xxxxxxxxxxxxx>
>> Cc: Chris von Recklinghausen <crecklin@xxxxxxxxxx>
>> Cc: Jason Baron <jbaron@xxxxxxxxxx>
>> Cc: Scott Wood <swood@xxxxxxxxxx>
>> Cc: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
>> Cc: Clark Williams <williams@xxxxxxxxxx>
>> Cc: x86@xxxxxxxxxx
>> Cc: linux-kernel@xxxxxxxxxxxxxxx
>> ---
>> kernel/jump_label.c | 16 ++++++++++++++++
>> 1 file changed, 16 insertions(+)
>>
>> diff --git a/kernel/jump_label.c b/kernel/jump_label.c
>> index e666a4d6642a..8b7bfbba4cef 100644
>> --- a/kernel/jump_label.c
>> +++ b/kernel/jump_label.c
>> @@ -36,12 +36,28 @@ static int jump_label_cmp(const void *a, const void *b)
>> const struct jump_entry *jea = a;
>> const struct jump_entry *jeb = b;
>>
>> + /*
>> + * Entrires are sorted by key.
>> + */

and this the typo above (just noticed),

>> if (jump_entry_key(jea) < jump_entry_key(jeb))
>> return -1;
>>
>> if (jump_entry_key(jea) > jump_entry_key(jeb))
>> return 1;
>>
>> +#ifdef HAVE_JUMP_LABEL_BATCH
>> + /*
>> + * In the batching mode, entries should also be sorted by the code
>> + * inside the already sorted list of entries, enabling a bsearch in
>> + * the vector.
>> + */
>> + if (jump_entry_code(jea) < jump_entry_code(jeb))
>> + return -1;
>> +
>> + if (jump_entry_code(jea) > jump_entry_code(jeb))
>> + return 1;
>> +#endif
>> +
>> return 0;
>> }
>
> The secondary sort order doesn't hurt, so we could leave the #ifdef out,
> not sure.

and remove the #ifdef, unless someone else things we need to keep it.

-- Daniel