[PATCH 2/7] Add 'likely' and 'unlikely' macros

Alan Coopersmith alan.coopersmith at oracle.com
Fri May 15 15:38:35 PDT 2015


On 05/15/15 03:34 PM, Peter Harris wrote:
> On 2015-05-15 01:48, Alan Coopersmith wrote:
>>
>> Speaking of which, something I've wondered about for a while, but never
>> had time to test, is if telling the server to optimize for valid requests
>> would make a difference, such as:
>
>>   #define REQUEST_AT_LEAST_SIZE(req) \
>> -    if ((sizeof(req) >> 2) > client->req_len )\
>> +    if (_X_UNLIKELY((sizeof(req) >> 2) > client->req_len )) \
>>            return(BadLength)
>
>> If anyone wants to try it out and report back, please do so!
>
> Slightly less than 1% improvement on x11perf -noop. Stable over multiple
> runs:
>
>    before           after         Operation
> ----------   -----------------   --------------------
> 13800000.0   13900000.0 (1.01)   X protocol NoOperation
>
> I didn't try the full patch or a full x11perf run, but it seems unlikely
> that it would be significant on a real load.

Thanks - since even a noop goes through a sizable stack, it's not that tight
of a loop going through this code, and I wouldn't be surprised if optimizers
already assume early return paths like that are uncommon error cases.

-- 
	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc


More information about the xorg-devel mailing list