Re: [PATCH V6 4/6] x86/alternative: Batch of patch operations

From: Daniel Bristot de Oliveira
Date: Wed Jun 12 2019 - 12:37:49 EST


On 12/06/2019 16:52, Peter Zijlstra wrote:
> On Wed, Jun 12, 2019 at 11:57:29AM +0200, Daniel Bristot de Oliveira wrote:
>
>> When a static key has more than one entry, these steps are called once for
>> each entry. The number of IPIs then is linear with regard to the number 'n' of
>> entries of a key: O(n*3), which is O(n).
>
>> Doing the update in this way, the number of IPI becomes O(3) with regard
>> to the number of keys, which is O(1).
>
> That's not quite true, what you're doing is n/X, which, in the end, is
> still O(n).
>
> It just so happens your X is 128, and so any n smaller than that ends up
> being 1.
>

Correct! In the v1, when I was using a (dynamic) linked list of keys, it was
O(1), now it is O(n).

Using an academic hat of easy assumptions, I could argue that:

"Doing the update in this way, the number of IPI becomes O(3) with regard to the
number of keys*, which is O(1).

* Given that the number of elements in the vector is larger than or equals to
the numbers of entries of a given key, O(n) otherwise."

Life is so easy when we can do such assumptions, like infinity memory :-)

So, yeah, with a fixed size vector, it is O(n) in the worst case, but still
"O(1)" in the vast majority of cases.

-- Daniel