CodeSamples: Make non-default combinations of cc and -O levels happy
cover CodeSamples: Make non-default combinations of cc and -O levels happy
While testing commit f2596972845b ("CodeSamples: Fix liburcu-signal support deprecation"), I observed build errors under Ubuntu 22.04.
Which prompted me to test various combinations of cc and optimization levels in building under CodeSamples/.
This patch set is a collection of fixes/adjustments to make such various choices happy.
Patch 1/6 is a preliminary change for ease of experimenting alternative GCC_ARGS such as "-g -Wall -O0", "-g -Wall -O1", and so on, under CodeSamples/.
Patch 2/6 fixes an issue around forward declaration of struct in .h file failing to satisfy compiler's assumption of accessing them from inline functions. Looks like this matters with some of gcc versions in low level optimization, but gcc of Ubuntu 22.04 hits this even at -O3. Actual declaration of a struct seems to be needed in front of inline functions who access such a struct.
Patch 3/6 adjusts indirection level of pointer arguments in xchg().
Patch 4/6 adds "static" to __inline__ functions.
Patch 5/6 fixes errors of duplicate symbols due to api.h being included in multiple .c files linked together. As a workaround, "#ifndef SUBOBJ" is added in api-pthreads.h and a flag of -DSUBOBJ is added in Makefiles to recipes of .c --> _sub.o.
Patch 6/6 removes variables whose final values are never used. Recent clang is pretty strict on set-but-unused variables.
To test against clang, you need to redirect cc --> clang by, for example, symlinking $HOME/bin/cc --> /usr/bin/clang or similar.
Thanks, Akira
--
Akira Yokosawa (6):
CodeSamples: Put $(GCC_ARGS) in cc argument list CodeSamples/datastruct: Move struct declaration from .c to .h CodeSamples/advsync: Add explicit type cast in xchg() CodeSamples/count: Add static to __inline__ function declarations
CodeSamples: Add #ifndef SUBOBJ to api-pthreads.h CodeSamples/datastruct/Issaquah: Remove unused variables
CodeSamples/advsync/q.c | 2 +- CodeSamples/advsync/wfenqueue.c | 2 +- CodeSamples/api-pthreads/api-pthreads.h | 14 ++++++++++++++ CodeSamples/count/count_end.c | 4 ++-- CodeSamples/count/count_end_rcu.c | 4 ++-- CodeSamples/count/count_stack.c | 6 +++--- CodeSamples/count/count_stat_atomic.c | 6 +++--- CodeSamples/datastruct/Issaquah/Makefile | 14 ++++++++++---- CodeSamples/datastruct/Issaquah/existence.c | 6 ------ CodeSamples/datastruct/Issaquah/existence.h | 7 ++++++- CodeSamples/datastruct/Issaquah/existence_test.c | 3 --- CodeSamples/datastruct/Issaquah/tree.c | 6 ------ CodeSamples/datastruct/hash/Makefile | 7 +++++-- CodeSamples/defer/Makefile | 7 +++++-- CodeSamples/defer/hazptr.h | 6 +++++- CodeSamples/intro/Makefile | 12 ++++++------ CodeSamples/locking/Makefile | 6 +++--- 17 files changed, 66 insertions(+), 46 deletions(-)
base-commit: 41e6a800d630336b1d8e614b3d11281e42e880c7
Signature · 1 line
2.34.1
PATCH 1/6 CodeSamples: Put $(GCC_ARGS) in cc argument list
There are a couple of Makefiles who don't have $(GCC_ARGS) in cc command lines. If you say:
make GCC_ARGS="-g -Wall -O0"
, the arguments are simply ignored by them.
Fill it in for ease of experiments/testing of compiler flags.
--- CodeSamples/intro/Makefile | 12 ++++++------ CodeSamples/locking/Makefile | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-)
CodeSamples/intro/Makefile +6 -6
@@ -15,22 +15,22 @@ endif include $(top)/recipes.mk initrace: initrace.c ../api.h - cc -g -Wall -o initrace initrace.c -lpthread + cc -g -Wall $(GCC_ARGS) -o initrace initrace.c -lpthread initraceperf: initraceperf.c ../api.h - cc -g -Wall -o initraceperf initraceperf.c -lpthread + cc -g -Wall $(GCC_ARGS) -o initraceperf initraceperf.c -lpthread lockinc: lockinc.c ../api.h - cc -g -Wall -o lockinc lockinc.c -lpthread + cc -g -Wall $(GCC_ARGS) -o lockinc lockinc.c -lpthread nakedinc: nakedinc.c ../api.h - cc -g -Wall -o nakedinc nakedinc.c -lpthread + cc -g -Wall $(GCC_ARGS) -o nakedinc nakedinc.c -lpthread perthreadinc: perthreadinc.c ../api.h - cc -g -Wall -o perthreadinc perthreadinc.c -lpthread + cc -g -Wall $(GCC_ARGS) -o perthreadinc perthreadinc.c -lpthread threadcreate: threadcreate.c ../api.h - cc -g -Wall -o threadcreate threadcreate.c -lpthread + cc -g -Wall $(GCC_ARGS) -o threadcreate threadcreate.c -lpthread clean: rm -f $(PROGS)
CodeSamples/locking/Makefile +3 -3
@@ -15,13 +15,13 @@ endif include $(top)/recipes.mk locked_list: locked_list.c ../api.h - cc -g -Wall -o locked_list locked_list.c + cc -g -Wall $(GCC_ARGS) -o locked_list locked_list.c xchglock: xchglock.c ../api.h - cc -g -Wall -o xchglock xchglock.c -lpthread + cc -g -Wall $(GCC_ARGS) -o xchglock xchglock.c -lpthread rec_tree_itr: rec_tree_itr.c ../api.h - cc -g -Wall -o rec_tree_itr rec_tree_itr.c -lpthread + cc -g -Wall $(GCC_ARGS) -o rec_tree_itr rec_tree_itr.c -lpthread clean: rm -f $(PROGS)
Signature · 1 line
2.34.1
PATCH 2/6 CodeSamples/datastruct: Move struct declaration from .c to .h
In reply to Akira YokosawaForward declaration of a struct in .h is insufficient if there is code that accesses the struct within the .h file depending on optimization levels.
GCC of Ubuntu 22.04 with -O0 as well as -O3 ends up in these pair of errors:
make[1]: Entering directory 'perfbook/CodeSamples/datastruct/Issaquah'
cc -g -O0 -Wall -o existence_test existence.c existence_test.c -lpthread -lurcu -lurcu-common -lurcu-signal
In file included from /usr/include/x86_64-linux-gnu/urcu/pointer.h:39,
from /usr/include/x86_64-linux-gnu/urcu-pointer.h:1,
from /usr/include/x86_64-linux-gnu/urcu/rculist.h:30,
from ../../api.h:847,
from existence.c:30:
existence.h: In function ‘existence_exists_relaxed’:
existence.h:54:32: error: invalid use of undefined type ‘struct existence’
54 | struct existence *ep = rcu_dereference(*epp);
| ^~~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/urcu/pointer.h:39,
from /usr/include/x86_64-linux-gnu/urcu-pointer.h:1,
from /usr/include/x86_64-linux-gnu/urcu/rculist.h:30,
from ../../api.h:847,
from existence_test.c:26:
existence.h: In function ‘existence_exists_relaxed’:
existence.h:54:32: error: invalid use of undefined type ‘struct existence’
54 | struct existence *ep = rcu_dereference(*epp);
| ^~~~~~~~~~~~~~~
make[1]: *** [Makefile:49: existence_test] Error 1
make[1]: Leaving directory 'perfbook/CodeSamples/datastruct/Issaquah'Move the declaration from .c to .h.
--- CodeSamples/datastruct/Issaquah/existence.c | 6 ------ CodeSamples/datastruct/Issaquah/existence.h | 7 ++++++- 2 files changed, 6 insertions(+), 7 deletions(-)
CodeSamples/datastruct/Issaquah/existence.c +0 -6
@@ -37,12 +37,6 @@/* Existence-switch array. */ const int existence_array[4 ] = {1 ,0 ,0 ,1 }; -/* Existence structure associated with each moving structure. */ -struct existence { -const int **existence_switch; -int offset; -}; -/* Existence-group structure associated with multi-structure change. */ struct existence_group {struct existence outgoing;
CodeSamples/datastruct/Issaquah/existence.h +6 -1
@@ -22,7 +22,12 @@#ifndef __EXISTENCE_H#define __EXISTENCE_H -struct existence ; +/* Existence structure associated with each moving structure. */ +struct existence { +const int **existence_switch; +int offset; +}; +struct existence_group ;void existence_wire_call_rcu (void );
Signature · 1 line
2.34.1
PATCH 3/6 CodeSamples/advsync: Add explicit type cast in xchg()
In reply to Akira YokosawaBuilding with CLANG, you'll see a couple of warnings while building under CodeSamples/ as follows:
cc -g -O3 -Wall -o q -DTEST q.c -lpthread
q.c:39:12: warning: incompatible pointer types passing 'struct el *'
to parameter of type 'struct el **'; take the address with & [-Wincompatible-pointer-types]
oldtail = xchg(&q->tail, p);
^~~~~~~~~~~~~~~~~
./../api.h:778:49: note: expanded from macro 'xchg'
^~~
1 warning generated.
and:
cc -g -O3 -Wall -o wfenqueue -DTEST wfenqueue.c -lpthread wfenqueue.c:38:9: warning: incompatible pointer types passing
'struct el *' to parameter of type 'struct el **'; take the address with & [-Wincompatible-pointer-types]
tail = xchg(&qp->tail, ep);
^~~~~~~~~~~~~~~~~~~
./../api.h:778:49: note: expanded from macro 'xchg'
^~~
1 warning generated.
This is due to indirection-level mismatch in the argument of xchg(). Add explicit cast and silence those warnings.
--- CodeSamples/advsync/q.c | 2 +- CodeSamples/advsync/wfenqueue.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
CodeSamples/advsync/q.c +1 -1
@@ -36,7 +36,7 @@ int q_push(struct el *p, struct queue *q)struct el **oldtail; p->next =NULL ; - oldtail =xchg (&q->tail, p); + oldtail =xchg (&q->tail, (struct el **)p); *oldtail = p;return 1 ; }
CodeSamples/advsync/wfenqueue.c +1 -1
@@ -35,7 +35,7 @@ int q_push(struct el *ep, struct queue *qp)struct el **tail; ep->next =NULL ; - tail =xchg (&qp->tail, ep); + tail =xchg (&qp->tail, (struct el **)ep); *tail = ep;return 1 ; }
Signature · 1 line
2.34.1
PATCH 4/6 CodeSamples/count: Add static to __inline__ function declarations
In reply to Akira YokosawaAt lower optimization levels of GCC, __inline__ functions without "static" cause build errors like below:
make[1]: Entering directory 'perfbook/CodeSamples/count'
cc -g -O0 -Wall -o count_end count_end.c -lpthread
/usr/bin/ld: /tmp/ccxpkcHA.o: in function `perftestrun':
perfbook/CodeSamples/count/counttorture.h:159: undefined reference to count_cleanup' /usr/bin/ld: /tmp/ccxpkcHA.o: in function main':
perfbook/CodeSamples/count/counttorture.h:248: undefined reference to `count_init'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:55: count_end] Error 1
make[1]: Leaving directory 'git/perfbook/CodeSamples/count'
Always put "static" to those function declarations.
While here, add __inline__ to read_count() of count_stack.c.
--- CodeSamples/count/count_end.c | 4 ++-- CodeSamples/count/count_end_rcu.c | 4 ++-- CodeSamples/count/count_stack.c | 6 +++--- CodeSamples/count/count_stat_atomic.c | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-)
CodeSamples/count/count_end.c +2 -2
@@ -48,7 +48,7 @@ static inline unsigned long read_count(void) }#ifndef FCV_SNIPPET -inline void count_init (void ) +static __inline__void count_init (void ) { }#endif /* FCV_SNIPPET */
@@ -73,7 +73,7 @@ void count_unregister_thread(int nthreadsexpected) //\lnlbl{unreg:b} }//\lnlbl{unreg:e} //\end{snippet} -inline void count_cleanup (void ) +static __inline__void count_cleanup (void ) { }
CodeSamples/count/count_end_rcu.c +2 -2
@@ -34,7 +34,7 @@ unsigned long __thread counter = 0; //\lnlbl{perthread:b}struct countarray *countarrayp =NULL ;DEFINE_SPINLOCK (final_mutex);//\lnlbl{perthread:e} -__inline__void inc_count (void )//\lnlbl{inc:b} +static __inline__void inc_count (void )//\lnlbl{inc:b} {WRITE_ONCE (counter, counter +1 ); }//\lnlbl{inc:e}
@@ -99,7 +99,7 @@ void count_unregister_thread(int nthreadsexpected) //\lnlbl{unreg:b} }//\lnlbl{unreg:e} //\end{snippet} -__inline__void count_cleanup (void ) +static __inline__void count_cleanup (void ) { }
CodeSamples/count/count_stack.c +3 -3
@@ -27,7 +27,7 @@ unsigned long *counterp[NR_THREADS] = { NULL };unsigned long finalcount =0 ;DEFINE_SPINLOCK (final_mutex); -__inline__void inc_count (void ) +static __inline__void inc_count (void ) {WRITE_ONCE (*counter,READ_ONCE (*counter) +1 );
@@ -47,7 +47,7 @@ unsigned long read_count(void)return sum; } -__inline__void count_init (void ) +static __inline__void count_init (void ) { }
@@ -71,7 +71,7 @@ void count_unregister_thread(int nthreadsexpected)spin_unlock (&final_mutex); } -__inline__void count_cleanup (void ) +static __inline__void count_cleanup (void ) { }
CodeSamples/count/count_stat_atomic.c +3 -3
@@ -28,7 +28,7 @@ void inc_count(void)atomic_inc (&__get_thread_var (counter)); } -__inline__unsigned long read_count (void ) +static __inline__unsigned long read_count (void ) {int t;unsigned long sum =0 ;
@@ -38,11 +38,11 @@ __inline__ unsigned long read_count(void)return sum; } -__inline__void count_init (void ) +static __inline__void count_init (void ) { } -__inline__void count_cleanup (void ) +static __inline__void count_cleanup (void ) { }
Signature · 1 line
2.34.1
PATCH 5/6 CodeSamples: Add #ifndef SUBOBJ to api-pthreads.h
In reply to Akira YokosawaWhen multiple object (.o) files, who include api.h, are linked together into an executable, you might see build errors at lower optimization levels like this:
make[1]: Entering directory 'perfbook/CodeSamples/defer'
...
cc -g -O0 -Wall -o route_hazptr route_hazptr.c hazptr.c ../lib/random.c -lpthread
/usr/bin/ld: /tmp/xxx.o:perfbook/CodeSamples/defer/../api.h:278:
multiple definition of `__thread_id_map';
/tmp/xxx.o:perfbook/CodeSamples/defer/../api.h:278: first defined here
/usr/bin/ld: /tmp/xxx.o:perfbook/CodeSamples/defer/../api.h:279:
multiple definition of `__thread_id_map_mutex';
/tmp/xxx.o:perfbook/CodeSamples/defer/../api.h:279: first defined here
...
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:132: route_hazptr] Error 1This is due exported symbols of:
o __thread_id_map[]
o __thread_id_map_mutex
o thread_id_key
o smp_processor_id
defined in api.h.
Avoid such duplicates by guarding their declarations by "#ifndef SUBOBJ" and put external reference in their #else cases.
Take care of HP in hazptr.h similarly.
In Makefiles, add recipes for building objects who don't have their own main() with the -DSUBOBJ flag appended.
--- CodeSamples/api-pthreads/api-pthreads.h | 14 ++++++++++++++ CodeSamples/datastruct/Issaquah/Makefile | 14 ++++++++++---- CodeSamples/datastruct/hash/Makefile | 7 +++++-- CodeSamples/defer/Makefile | 7 +++++-- CodeSamples/defer/hazptr.h | 6 +++++- 5 files changed, 39 insertions(+), 9 deletions(-)
CodeSamples/api-pthreads/api-pthreads.h +14 -0
@@ -159,8 +159,14 @@ typedef pthread_t thread_id_t;#define __THREAD_ID_MAP_EMPTY 0#define __THREAD_ID_MAP_WAITING 1 + +#ifndef SUBOBJ thread_id_t __thread_id_map[NR_THREADS ];spinlock_t __thread_id_map_mutex; +#else +extern thread_id_t __thread_id_map[NR_THREADS ]; +extern spinlock_t __thread_id_map_mutex; +#endif #define for_each_thread (t) \ for (t = 0; t < NR_THREADS; t++)
@@ -175,7 +181,11 @@ spinlock_t __thread_id_map_mutex;if ((((tid) = __thread_id_map[t]) != __THREAD_ID_MAP_EMPTY) && \ ((tid) != __THREAD_ID_MAP_WAITING)) +#ifndef SUBOBJ pthread_key_t thread_id_key; +#else +extern pthread_key_t thread_id_key; +#endif static __inline__int num_online_threads (void ) {
@@ -368,7 +378,11 @@ static __inline__ long long get_microseconds(void) } __per_cpu_##name[NR_CPUS]#define DECLARE_PER_CPU (type, name) extern DEFINE_PER_CPU(type, name) +#ifndef SUBOBJ DEFINE_PER_THREAD (int, smp_processor_id); +#else +DECLARE_PER_THREAD (int, smp_processor_id); +#endif static __inline__int smp_processor_id (void ) {
CodeSamples/datastruct/Issaquah/Makefile +10 -4
@@ -45,11 +45,17 @@ LURCU_SIG := $(shell pkg-config --libs liburcu-signal 2>/dev/null) # -DUSE_JEMALLOC # Verify by using the nm command and searching output for malloc. -existence_test: existence.c existence_test.c - cc $(GCC_ARGS) -o existence_test existence.c existence_test.c -lpthread -lurcu $(LURCU_SIG) +existence_sub.o: existence.c existence.h ../../api.h + cc $(GCC_ARGS) -o existence_sub.o -c -DSUBOBJ existence.c -treetorture: tree.c existence.c spinlockmult.c $(LIB)/random.c ../../api.h treetorture.h treetorturetrace.h $(LIB)/random.h existence.h tree.h - cc $(GCC_ARGS) -o treetorture tree.c existence.c spinlockmult.c $(LIB)/random.c -lpthread -lurcu $(LURCU_SIG) +existence_test: existence_sub.o existence_test.c ../../api.h + cc $(GCC_ARGS) -o existence_test existence_sub.o existence_test.c -lpthread -lurcu $(LURCU_SIG) + +spinlockmult_sub.o: spinlockmult.c spinlockmult.h ../../api.h + cc $(GCC_ARGS) -o spinlockmult_sub.o -c -DSUBOBJ spinlockmult.c + +treetorture: tree.c existence_sub.o spinlockmult_sub.o $(LIB)/random.c ../../api.h treetorture.h treetorturetrace.h $(LIB)/random.h existence.h tree.h + cc $(GCC_ARGS) -o treetorture tree.c existence_sub.o spinlockmult_sub.o $(LIB)/random.c -lpthread -lurcu $(LURCU_SIG) clean: rm -f $(PROGS)
CodeSamples/datastruct/hash/Makefile +5 -2
@@ -47,8 +47,11 @@ hash_bkt_qsbr: hash_bkt_rcu.c ../../api.h hashtorture.h hash_bkt_rcu: hash_bkt_rcu.c ../../api.h hashtorture.h cc $(GCC_ARGS) -DTEST_HASH -o hash_bkt_rcu hash_bkt_rcu.c $(LIB)/random.c -lpthread -lurcu $(LURCU_SIG) -hash_bkt_hazptr: hash_bkt_hazptr.c ../../defer/hazptr.c ../../defer/hazptr.h ../../api.h hashtorture.h - cc $(GCC_ARGS) -DTEST_HASH -o hash_bkt_hazptr hash_bkt_hazptr.c ../../defer/hazptr.c $(LIB)/random.c -lpthread +../../defer/hazptr_sub.o: ../../defer/hazptr.c ../../defer/hazptr.h ../../api.h + $(MAKE) -C ../../defer hazptr_sub.o + +hash_bkt_hazptr: hash_bkt_hazptr.c ../../defer/hazptr_sub.o ../../api.h hashtorture.h + cc $(GCC_ARGS) -DTEST_HASH -o hash_bkt_hazptr hash_bkt_hazptr.c ../../defer/hazptr_sub.o $(LIB)/random.c -lpthread hash_global: hash_global.c ../../api.h hashtorture.h cc $(GCC_ARGS) -DTEST_HASH -o hash_global hash_global.c $(LIB)/random.c -lpthread
CodeSamples/defer/Makefile +5 -2
@@ -128,8 +128,11 @@ rcu_sig: rcu_sig.c rcu_sig.h ../api.h rcutorture.h rcu_ts: rcu_ts.c rcu_ts.h ../api.h rcutorture.h cc $(GCC_ARGS) -o rcu_ts -DTEST rcu_ts.c -lpthread -route_hazptr: route_hazptr.c hazptr.c hazptr.h ../api.h ../lib/random.h ../lib/random.c routetorture.h - cc $(GCC_ARGS) -o route_hazptr route_hazptr.c hazptr.c ../lib/random.c -lpthread +hazptr_sub.o: hazptr.c hazptr.h ../api.h + cc $(GCC_ARGS) -o hazptr_sub.o -c -DSUBOBJ hazptr.c + +route_hazptr: route_hazptr.c hazptr_sub.o ../api.h ../lib/random.h ../lib/random.c routetorture.h + cc $(GCC_ARGS) -o route_hazptr route_hazptr.c hazptr_sub.o ../lib/random.c -lpthread route_rcu: route_rcu.c ../api.h ../lib/random.h ../lib/random.c routetorture.h cc $(GCC_ARGS) -o route_rcu route_rcu.c ../lib/random.c -lpthread -lurcu $(LURCU_SIG)
CodeSamples/defer/hazptr.h +5 -1
@@ -52,8 +52,12 @@ typedef struct hazard_pointer_s { } hazard_pointer;/* Must be dynamically initialized to be an array of size H. */ +#ifndef SUBOBJ hazard_pointer *HP ; - +#else +extern hazard_pointer *HP ; +#endif +void hazptr_init (void );void hazptr_thread_exit (void );void hazptr_scan ();
Signature · 1 line
2.34.1
PATCH 6/6 CodeSamples/datastruct/Issaquah: Remove unused variables
In reply to Akira YokosawaRecent versions of CLANG emit warnings like:
- variable 'i' set but not used [-Wunused-but-set-variable]
- warning: variable 'tries' set but not used [-Wunused-but-set-variable]
Silence them by removing those unnecessary variables and related code incrementing them.
--- CodeSamples/datastruct/Issaquah/existence_test.c | 3 --- CodeSamples/datastruct/Issaquah/tree.c | 6 ------ 2 files changed, 9 deletions(-)
CodeSamples/datastruct/Issaquah/existence_test.c +0 -3
@@ -36,8 +36,6 @@ struct existence_group *egp;static void *scan_existence (void *arg) { -int i =0 ; -for (;;) {if (!existence_exists (&outgoing)) {BUG_ON (!existence_exists (&incoming));
@@ -47,7 +45,6 @@ static void *scan_existence(void *arg)BUG_ON (existence_exists (&outgoing));break ; } - i++; }/* printf("scan_existence(): %d loops\n", i); */ return NULL ;
CodeSamples/datastruct/Issaquah/tree.c +0 -6
@@ -504,10 +504,8 @@ void *tree_lookup(struct treeroot *trp, int key, void (*func)(void *data))struct treenode *par;spinlock_t *lockp =NULL ;int wantdelay =0 ; -int tries =0 ; retry: - tries++;rcu_read_lock (); cur =_tree_lookup (trp, key, &par);TREE_BUG_ON (cur ==NULL );
@@ -580,7 +578,6 @@ int tree_insert_existence(struct treeroot *trp, int key, void *data,struct treenode *par;int ret =0 ;spinlock_t *lockp[2 ]; -int tries =0 ;int wantdelay =0 ;TREE_BUG_ON (data ==NULL );
@@ -588,7 +585,6 @@ int tree_insert_existence(struct treeroot *trp, int key, void *data,if (!new)return -ENOMEM ; retry: - tries++;rcu_read_lock (); cur =_tree_lookup (trp, key, &par);TREE_BUG_ON (cur ==NULL || par ==NULL );
@@ -660,11 +656,9 @@ static int tree_delete_existence(struct treeroot *trp, int key,struct treenode *par;spinlock_t *lockp[2 ];int ret = -ENOENT ; -int tries =0 ;int wantdelay =0 ; retry: - tries++;rcu_read_lock (); cur =_tree_lookup (trp, key, &par);TREE_BUG_ON (cur ==NULL || par ==NULL );
Signature · 1 line
2.34.1
Paul E. McKenney
AppliedQuoted 29 lines · Akira Yokosawa
While testing commit
f2596972845b("CodeSamples: Fix liburcu-signal support deprecation"), I observed build errors under Ubuntu 22.04.Which prompted me to test various combinations of cc and optimization levels in building under CodeSamples/.
This patch set is a collection of fixes/adjustments to make such various choices happy.
Patch 1/6 is a preliminary change for ease of experimenting alternative
GCC_ARGSsuch as "-g -Wall -O0", "-g -Wall -O1", and so on, under CodeSamples/.Patch 2/6 fixes an issue around forward declaration of struct in .h file failing to satisfy compiler's assumption of accessing them from inline functions. Looks like this matters with some of gcc versions in low level optimization, but gcc of Ubuntu 22.04 hits this even at -O3. Actual declaration of a struct seems to be needed in front of inline functions who access such a struct.
Patch 3/6 adjusts indirection level of pointer arguments in
xchg().Patch 4/6 adds "static" to
__inline__functions.Patch 5/6 fixes errors of duplicate symbols due to
api.hbeing included in multiple .c files linked together. As a workaround, "#ifndef SUBOBJ" is added inapi-pthreads.hand a flag of -DSUBOBJ is added in Makefiles to recipes of .c --> _sub.o.
Quoted 5 lines
Patch 6/6 removes variables whose final values are never used. Recent clang is pretty strict on set-but-unused variables.
To test against clang, you need to redirect cc --> clang by, for example, symlinking $HOME/bin/cc -->
/usr/bin/clangor similar.
Queued and pushed, thank you very much! And happy perfect-square new year!
Thanx, Paul
Quoted 34 lines
Thanks, Akira
--
Akira Yokosawa (6):
CodeSamples: Put $(GCC_ARGS) in cc argument list CodeSamples/datastruct: Move struct declaration from .c to .h CodeSamples/advsync: Add explicit type cast inxchg()CodeSamples/count: Add static to__inline__function declarations
CodeSamples: Add #ifndef SUBOBJ toapi-pthreads.hCodeSamples/datastruct/Issaquah: Remove unused variablesCodeSamples/advsync/q.c | 2 +- CodeSamples/advsync/wfenqueue.c | 2 +- CodeSamples/api-pthreads/api-pthreads.h | 14 ++++++++++++++ CodeSamples/count/count_end.c | 4 ++-- CodeSamples/count/count_end_rcu.c | 4 ++-- CodeSamples/count/count_stack.c | 6 +++--- CodeSamples/count/count_stat_atomic.c | 6 +++--- CodeSamples/datastruct/Issaquah/Makefile | 14 ++++++++++---- CodeSamples/datastruct/Issaquah/existence.c | 6 ------ CodeSamples/datastruct/Issaquah/existence.h | 7 ++++++- CodeSamples/datastruct/Issaquah/existence_test.c | 3 --- CodeSamples/datastruct/Issaquah/tree.c | 6 ------ CodeSamples/datastruct/hash/Makefile | 7 +++++-- CodeSamples/defer/Makefile | 7 +++++-- CodeSamples/defer/hazptr.h | 6 +++++- CodeSamples/intro/Makefile | 12 ++++++------ CodeSamples/locking/Makefile | 6 +++--- 17 files changed, 66 insertions(+), 46 deletions(-)base-commit:
41e6a800d630336b1d8e614b3d11281e42e880c7Signature · 1 line
2.34.1
On Sun, 5 Jan 2025 11:02:11 -0800, Paul E. McKenney wrote:
[...]
Quoted 3 lines
Queued and pushed, thank you very much! And happy perfect-square new year!
You mean: 45**2 == 2025 ?
You can go further:
(1+2+3+4+5+6+7+8+9)**2 == 2025
, and
1**3 + 2**3 + 3**3 + 4**3 + 5**3 + 6**3 + 7**3 + 8**3 + 9**3 == 2025
Happy new year!
Akira
Quoted 8 lines · Akira Yokosawa
On Sun, 5 Jan 2025 11:02:11 -0800, Paul E. McKenney wrote:
[...]Quoted 3 lines
Queued and pushed, thank you very much! And happy perfect-square new year!
You mean: 45**2 == 2025 ?
Quoted 7 lines
You can go further:
(1+2+3+4+5+6+7+8+9)**2 == 2025, and
1**3 + 2**3 + 3**3 + 4**3 + 5**3 + 6**3 + 7**3 + 8**3 + 9**3 == 2025
And (int(2025 / 100) + 2025 % 100)**2 == 2025.
This is more rare that the others, the last time being the year 1 and the next time being the year 3025.
And much less rarely, 2025 == 5^2 + 20^2 + 40^2.
I am not sure why there is so much interest in year-2025 numerology, but it can be fun. ;-)
Thanx, Paul
Quoted 4 lines
Happy new year!
Akira