Sergey Senozhatsky
166a0f780a
lib/bsearch.c: micro-optimize pivot position calculation
There is a slightly faster way (in terms of the number of instructions
being used) to calculate the position of a middle element, preserving
integer overflow safeness.
./scripts/bloat-o-meter lib/bsearch.o.old lib/bsearch.o.new
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-24 (-24)
function old new delta
bsearch 122 98 -24
TEST
INT array of size 100001, elements [0..100000]. gcc 7.1, Os, x86_64.
a) bsearch() of existing key "100001 - 2":
BASE
====
$ perf stat ./a.out
Performance counter stats for './a.out':
619.445196 task-clock:u (msec) # 0.999 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
133 page-faults:u # 0.215 K/sec
1,949,517,279 cycles:u # 3.147 GHz (83.06%)
181,017,938 stalled-cycles-frontend:u # 9.29% frontend cycles idle (83.05%)
82,959,265 stalled-cycles-backend:u # 4.26% backend cycles idle (67.02%)
4,355,706,383 instructions:u # 2.23 insn per cycle
# 0.04 stalled cycles per insn (83.54%)
1,051,539,242 branches:u # 1697.550 M/sec (83.54%)
15,263,381 branch-misses:u # 1.45% of all branches (83.43%)
0.620082548 seconds time elapsed
PATCHED
=======
$ perf stat ./a.out
Performance counter stats for './a.out':
475.097316 task-clock:u (msec) # 0.999 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
135 page-faults:u # 0.284 K/sec
1,487,467,717 cycles:u # 3.131 GHz (82.95%)
186,537,162 stalled-cycles-frontend:u # 12.54% frontend cycles idle (82.93%)
28,797,869 stalled-cycles-backend:u # 1.94% backend cycles idle (67.10%)
3,807,564,203 instructions:u # 2.56 insn per cycle
# 0.05 stalled cycles per insn (83.57%)
1,049,344,291 branches:u # 2208.693 M/sec (83.60%)
5,485 branch-misses:u # 0.00% of all branches (83.58%)
0.475760235 seconds time elapsed
b) bsearch() of un-existing key "100001 + 2":
BASE
====
$ perf stat ./a.out
Performance counter stats for './a.out':
499.244480 task-clock:u (msec) # 0.999 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
132 page-faults:u # 0.264 K/sec
1,571,194,855 cycles:u # 3.147 GHz (83.18%)
13,450,980 stalled-cycles-frontend:u # 0.86% frontend cycles idle (83.18%)
21,256,072 stalled-cycles-backend:u # 1.35% backend cycles idle (66.78%)
4,171,197,909 instructions:u # 2.65 insn per cycle
# 0.01 stalled cycles per insn (83.68%)
1,009,175,281 branches:u # 2021.405 M/sec (83.79%)
3,122 branch-misses:u # 0.00% of all branches (83.37%)
0.499871144 seconds time elapsed
PATCHED
=======
$ perf stat ./a.out
Performance counter stats for './a.out':
399.023499 task-clock:u (msec) # 0.998 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
134 page-faults:u # 0.336 K/sec
1,245,793,991 cycles:u # 3.122 GHz (83.39%)
11,529,273 stalled-cycles-frontend:u # 0.93% frontend cycles idle (83.46%)
12,116,311 stalled-cycles-backend:u # 0.97% backend cycles idle (66.92%)
3,679,710,005 instructions:u # 2.95 insn per cycle
# 0.00 stalled cycles per insn (83.47%)
1,009,792,625 branches:u # 2530.660 M/sec (83.46%)
2,590 branch-misses:u # 0.00% of all branches (83.12%)
0.399733539 seconds time elapsed
Link: http://lkml.kernel.org/r/20170607150457.5905-1-sergey.senozhatsky@gmail.com
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-10 16:32:35 -07:00
..
2016-03-17 21:38:27 -07:00
2017-02-27 18:43:46 -08:00
2017-02-24 17:46:57 -08:00
2014-09-28 11:08:01 +02:00
2016-11-25 12:57:50 +11:00
2017-05-16 10:01:57 +05:30
2014-06-04 16:54:18 -07:00
2015-09-10 13:29:01 -07:00
2017-05-08 17:15:12 -07:00
2012-10-08 13:50:18 +10:30
2013-04-29 18:28:19 -07:00
2016-05-17 09:33:39 -07:00
2016-04-06 14:06:48 +01:00
2017-02-24 17:46:57 -08:00
locking/atomic: Implement atomic{,64,_long}_fetch_{add,sub,and,andnot,or,xor}{,_relaxed,_acquire,_release}()
2016-06-16 10:48:32 +02:00
2014-12-13 12:42:51 -08:00
2012-09-10 11:13:16 -07:00
2011-03-11 14:25:50 +00:00
2017-07-10 16:32:34 -07:00
2014-12-22 16:43:06 +00:00
2017-07-10 16:32:35 -07:00
2015-11-23 09:44:58 +01:00
2017-03-30 09:37:20 +02:00
2013-06-19 17:54:06 +02:00
2013-03-22 16:41:20 -07:00
2016-07-03 00:57:23 -04:00
2012-03-07 15:04:04 -05:00
2016-03-13 23:55:13 -04:00
2014-04-03 16:21:12 -07:00
2012-02-02 10:34:23 +11:00
2017-06-23 16:15:55 -07:00
2014-03-20 10:11:35 -04:00
2011-10-29 21:20:22 +02:00
2015-05-27 15:22:15 +02:00
2017-05-15 10:15:23 +02:00
2017-06-09 11:52:07 +02:00
2014-05-16 14:26:52 -04:00
2011-06-03 15:01:06 -04:00
2017-02-24 17:46:57 -08:00
2012-03-23 16:58:38 -07:00
2017-02-24 17:46:57 -08:00
2015-05-26 15:26:43 +02:00
2015-05-30 22:42:24 -07:00
2012-03-07 15:04:04 -05:00
2015-06-11 15:08:32 +02:00
2013-06-26 12:10:56 +02:00
2017-03-02 08:42:36 +01:00
2012-03-07 15:04:04 -05:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2017-02-24 17:46:57 -08:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-07-17 16:39:54 -07:00
2017-04-24 13:53:13 -05:00
2017-03-02 10:09:00 +11:00
2015-11-16 14:42:12 -05:00
2017-05-09 15:40:28 -07:00
2017-06-28 06:55:01 -07:00
2017-06-28 06:54:41 -07:00
2017-03-02 08:42:34 +01:00
2016-08-04 08:50:07 -04:00
2015-02-12 18:54:15 -08:00
2016-06-08 11:04:19 +02:00
2017-07-06 07:02:24 -04:00
2017-07-10 16:32:35 -07:00
2017-05-08 17:15:12 -07:00
2014-04-30 19:49:37 +01:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2017-02-24 17:46:57 -08:00
2014-01-21 23:17:20 -08:00
2017-06-20 15:42:32 -04:00
2016-05-20 17:58:30 -07:00
2015-02-13 21:21:35 -08:00
2016-10-27 18:43:43 -07:00
2017-02-24 17:46:57 -08:00
2017-02-24 17:46:57 -08:00
2015-11-06 17:50:42 -08:00
2016-06-08 15:01:02 +02:00
2017-02-13 21:44:10 -05:00
2013-04-29 18:28:19 -07:00
2017-07-10 16:32:35 -07:00
2015-02-12 18:54:15 -08:00
2016-01-20 17:09:18 -08:00
2014-04-07 16:36:11 -07:00
2015-11-05 16:34:48 -08:00
2016-08-02 19:35:07 -04:00
2017-03-09 11:48:47 -08:00
2017-07-07 20:39:20 -07:00
2016-10-15 10:03:15 -07:00
2012-03-07 15:04:04 -05:00
2017-03-02 08:42:38 +01:00
2012-05-02 00:04:06 -07:00
2016-01-16 11:17:27 -08:00
2017-07-07 09:44:06 -07:00
2017-07-10 16:32:35 -07:00
2016-07-28 16:07:41 -07:00
2017-05-16 08:44:22 -03:00
2016-12-14 16:04:08 -08:00
2014-08-08 15:57:25 -07:00
2016-02-07 22:18:47 -08:00
2017-05-25 18:30:51 +02:00
2017-03-22 20:11:35 -06:00
2017-07-10 16:32:34 -07:00
2011-10-31 17:30:56 -07:00
2015-03-31 09:45:50 -06:00
2017-06-08 17:36:03 +08:00
2017-02-24 17:46:56 -08:00
2017-05-08 17:15:10 -07:00
2015-11-06 17:50:42 -08:00
2017-06-08 10:35:50 +02:00
2017-06-08 10:35:50 +02:00
2016-11-16 10:15:10 +01:00
2015-11-25 09:22:02 -07:00
2017-07-07 19:38:17 -07:00
2012-07-30 17:25:22 -07:00
2012-07-30 17:25:16 -07:00
2014-06-25 17:45:43 -07:00
2015-12-03 11:49:23 -05:00
2017-06-20 13:30:15 -04:00
2017-05-19 14:42:19 +02:00
2016-05-19 19:12:14 -07:00
2013-04-09 14:13:05 -04:00
2012-07-30 17:25:22 -07:00
2012-12-14 10:32:52 +11:00
2013-05-05 14:38:00 -07:00
2015-10-08 05:26:36 -07:00
2017-02-03 16:35:42 -05:00
2016-12-06 10:17:03 +02:00
2015-09-08 14:35:59 -07:00
2017-06-20 15:42:32 -04:00
2017-03-02 08:42:34 +01:00
2013-11-13 12:09:11 +09:00
2017-03-22 19:18:43 -07:00
2017-03-02 08:42:27 +01:00
2012-07-30 17:25:22 -07:00
2017-01-23 09:17:12 +01:00
2017-05-03 15:52:09 -07:00
2016-10-15 10:03:15 -07:00
2016-08-02 19:35:06 -04:00
2012-05-17 15:18:37 +02:00
2014-01-23 16:37:03 -08:00
2017-02-24 17:46:57 -08:00
2014-01-21 23:17:20 -08:00
2017-06-28 18:54:46 +02:00
2017-07-10 16:32:35 -07:00
2017-04-14 14:06:52 -06:00
2017-06-15 14:30:14 +02:00
2015-12-23 14:27:20 -05:00
2016-04-15 16:53:14 -04:00
2015-08-24 14:28:01 -06:00
2015-03-23 22:12:08 -04:00
2017-02-22 16:41:30 -08:00
2017-01-09 13:58:57 -05:00
2017-05-23 10:01:38 +02:00
2017-02-24 17:46:57 -08:00
2016-11-11 08:12:37 -08:00
2015-02-12 18:54:16 -08:00
2016-04-21 10:47:26 +10:00
2017-05-04 18:03:51 -07:00
2016-10-11 15:06:30 -07:00
2017-05-15 23:40:22 -04:00
2017-01-15 12:37:24 -05:00
2017-03-24 07:43:35 +01:00
2017-07-10 16:32:34 -07:00
2017-06-20 13:30:14 -04:00
2017-01-25 11:52:34 +01:00
2016-09-01 17:52:01 -07:00
2016-01-20 17:09:18 -08:00
2017-03-31 17:13:30 -07:00
2017-05-08 17:15:10 -07:00
2014-01-23 16:36:57 -08:00
2017-02-26 11:03:38 -05:00
2016-03-15 16:55:16 -07:00
2016-08-08 12:52:42 -07:00
2017-01-09 13:58:57 -05:00
2017-05-08 17:15:10 -07:00
2015-08-03 11:51:12 +02:00
2016-02-09 10:27:29 +01:00
2017-05-01 09:36:30 +02:00
2017-06-05 16:59:04 +02:00
2015-09-10 13:29:01 -07:00
2016-02-03 08:28:43 -08:00
2014-10-14 02:18:14 +02:00
2017-01-20 08:03:42 +01:00
2016-08-02 17:31:41 -04:00
2016-01-20 17:09:18 -08:00
2016-09-09 16:08:46 +01:00
2017-06-29 22:21:20 -04:00
2017-06-05 16:59:05 +02:00
2017-07-07 10:37:54 -07:00
2016-09-21 00:22:59 -04:00