Re: [PATCH v2 16/19] locking/lockdep: Use function pointer to avoid constant checks

From: Bart Van Assche
Date: Tue Mar 19 2019 - 12:56:54 EST


On Mon, 2019-03-18 at 16:57 +-0800, Yuyang Du wrote:
+AD4 +-static inline struct list+AF8-head +ACo-get+AF8-forward+AF8-dep(struct lock+AF8-list +ACo lock)
+AD4 +-+AHs
+AD4 +- return +ACY-lock-+AD4-class-+AD4-locks+AF8-after+ADs
+AD4 +-+AH0
+AD4 +-
+AD4 +-static inline struct list+AF8-head +ACo-get+AF8-backward+AF8-dep(struct lock+AF8-list +ACo lock)
+AD4 +-+AHs
+AD4 +- return +ACY-lock-+AD4-class-+AD4-locks+AF8-before+ADs
+AD4 +-+AH0
+AD4 +-
+AD4 static int +AF8AXw-bfs(struct lock+AF8-list +ACo-source+AF8-entry,
+AD4 void +ACo-data,
+AD4 int (+ACo-match)(struct lock+AF8-list +ACo-entry, void +ACo-data),
+AD4 struct lock+AF8-list +ACoAKg-target+AF8-entry,
+AD4 - int forward)
+AD4 +- struct list+AF8-head +ACo(+ACo-get+AF8-dep)(struct lock+AF8-list +ACo lock))
+AD4 +AHs
+AD4 struct lock+AF8-list +ACo-entry+ADs
+AD4 struct lock+AF8-list +ACo-lock+ADs
+AD4 +AEAAQA -1392,11 +-1402,7 +AEAAQA static int +AF8AXw-bfs(struct lock+AF8-list +ACo-source+AF8-entry,
+AD4 goto exit+ADs
+AD4 +AH0
+AD4
+AD4 - if (forward)
+AD4 - head +AD0 +ACY-source+AF8-entry-+AD4-class-+AD4-locks+AF8-after+ADs
+AD4 - else
+AD4 - head +AD0 +ACY-source+AF8-entry-+AD4-class-+AD4-locks+AF8-before+ADs
+AD4 -
+AD4 +- head +AD0 get+AF8-dep(source+AF8-entry)+ADs
+AD4 if (list+AF8-empty(head))
+AD4 goto exit+ADs
+AD4
+AD4 +AEAAQA -1410,10 +-1416,7 +AEAAQA static int +AF8AXw-bfs(struct lock+AF8-list +ACo-source+AF8-entry,
+AD4 goto exit+ADs
+AD4 +AH0
+AD4
+AD4 - if (forward)
+AD4 - head +AD0 +ACY-lock-+AD4-class-+AD4-locks+AF8-after+ADs
+AD4 - else
+AD4 - head +AD0 +ACY-lock-+AD4-class-+AD4-locks+AF8-before+ADs
+AD4 +- head +AD0 get+AF8-dep(lock)+ADs
+AD4
+AD4 DEBUG+AF8-LOCKS+AF8-WARN+AF8-ON(+ACE-irqs+AF8-disabled())+ADs
+AD4
+AD4 +AEAAQA -1445,7 +-1448,7 +AEAAQA static inline int +AF8AXw-bfs+AF8-forwards(struct lock+AF8-list +ACo-src+AF8-entry, void +ACo-data,
+AD4 int (+ACo-match)(struct lock+AF8-list +ACo-entry, void +ACo-data),
+AD4 struct lock+AF8-list +ACoAKg-target+AF8-entry)
+AD4 +AHs
+AD4 - return +AF8AXw-bfs(src+AF8-entry, data, match, target+AF8-entry, 1)+ADs
+AD4 +- return +AF8AXw-bfs(src+AF8-entry, data, match, target+AF8-entry, get+AF8-forward+AF8-dep)+ADs
+AD4
+AD4 +AH0
+AD4
+AD4 +AEAAQA -1453,7 +-1456,7 +AEAAQA static inline int +AF8AXw-bfs+AF8-backwards(struct lock+AF8-list +ACo-src+AF8-entry, void +ACo-data,
+AD4 int (+ACo-match)(struct lock+AF8-list +ACo-entry, void +ACo-data),
+AD4 struct lock+AF8-list +ACoAKg-target+AF8-entry)
+AD4 +AHs
+AD4 - return +AF8AXw-bfs(src+AF8-entry, data, match, target+AF8-entry, 0)+ADs
+AD4 +- return +AF8AXw-bfs(src+AF8-entry, data, match, target+AF8-entry, get+AF8-backward+AF8-dep)+ADs
+AD4
+AD4 +AH0

I think this patch makes the code harder to read. Additionally, if the compiler doesn't
do conditional folding, this patch introduces an indirect branch and hence will make the
lockdep code slower.

Bart.