[Cocci] [PATCH] coccinelle: api: add sprintf() support to device_attr_show
It's safe to use sprintf() for simple cases in device_attr_show type of functions. Add support for sprintf() in patch mode to the device_attr_show.cocci script to print numbers and pointers. Signed-off-by: Denis Efremov --- Interesting enough that with this patch coccinelle starts to skip patch generation in some cases. For example, it skips patch for drivers/base/core.c This is an unexpected result for me. scripts/coccinelle/api/device_attr_show.cocci | 30 +++ 1 file changed, 30 insertions(+) diff --git a/scripts/coccinelle/api/device_attr_show.cocci b/scripts/coccinelle/api/device_attr_show.cocci index d8ec4bb8ac41..1248b8c76cfe 100644 --- a/scripts/coccinelle/api/device_attr_show.cocci +++ b/scripts/coccinelle/api/device_attr_show.cocci @@ -30,15 +30,45 @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf) @rp depends on patch@ identifier show, dev, attr, buf; +constant str; @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf) { <... +( + return +- snprintf ++ sprintf + (buf, +- \(PAGE_SIZE\|PAGE_SIZE - 1\), + str); +| + return +- snprintf ++ sprintf + (buf, +- \(PAGE_SIZE\|PAGE_SIZE - 1\), + \("%i"\|"%i\n"\|"%li"\|"%li\n"\|"%lli"\|"%lli\n"\| + "%d"\|"%d\n"\|"%ld"\|"%ld\n"\|"%lld"\|"%lld\n"\| + "%u"\|"%u\n"\|"%lu"\|"%lu\n"\|"%llu"\|"%llu\n"\| + "%x"\|"%x\n"\|"%lx"\|"%lx\n"\|"%llx"\|"%llx\n"\| + "%X"\|"%X\n"\|"%lX"\|"%lX\n"\|"%llX"\|"%llX\n"\| + "0x%x"\|"0x%x\n"\|"0x%lx"\|"0x%lx\n"\|"0x%llx"\|"0x%llx\n"\| + "0x%X"\|"0x%X\n"\|"0x%lX"\|"0x%lX\n"\|"0x%llX"\|"0x%llX\n"\| + "%02x\n"\|"%03x\n"\|"%04x\n"\|"%08x\n"\| + "%02X\n"\|"%03X\n"\|"%04X\n"\|"%08X\n"\| + "0x%02x\n"\|"0x%03x\n"\|"0x%04x\n"\|"0x%08x\n"\| + "0x%02X\n"\|"0x%03X\n"\|"0x%04X\n"\|"0x%08X\n"\| + "%zd"\|"%zd\n"\|"%zu"\|"%zu\n"\|"%zx"\|"%zx\n"\| + "%c"\|"%c\n"\|"%p"\|"%p\n"\|"%pU\n"\|"%pUl\n"\|"%hu\n"\), + ...); +| return - snprintf + scnprintf (...); +) ...> } -- 2.26.2 ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] scripts: coccicheck: Change default value for parallelism
On Thu, 13 Aug 2020, Sumera Priyadarsini wrote: > > > On Thu, 13 Aug, 2020, 1:45 AM Julia Lawall, wrote: > > > On Wed, 12 Aug 2020, Sumera Priyadarsini wrote: > > > By default, coccicheck utilizes all available threads to implement > > parallelisation. However, when hyperthreading is enabled, this leads > > to all threads per core being occupied resulting in longer wall-clock > > times and higher power consumption. > > I have the feeling that the above sentence is not quite optimal. > Actually, using all of the available hardware threads would not be a bad > thing, if it was giving a benefit. The point is that it doesn't. It > makes the performance worse instead. > > > How does this sound? > > However, when all available threads are used, a decrease in performance was > noted. The elapsed time was minimum when at most one thread per core was > used. This looks better, thanks. julia > > > > > > Hence, to improve performance, > > modify coccicheck to use only one thread per core atmost. > > "atmost" is not a word. It would be clearer to say "to use at most one > thread per core". > > > In the cases where the total number of threads is more than 8 and > > hyperthreading is enabled, it was observed that optimum performance > > is achieved around one-fourth of the total number of cores. > > Modify the script further to accommodate this use case. > > It would be nice to give some performance numbers and some information > about the machine used. > > > Alright, will add this. > > > thanks, > julia > > > > > Signed-off-by: Sumera Priyadarsini > > --- > > scripts/coccicheck | 9 + > > 1 file changed, 9 insertions(+) > > > > diff --git a/scripts/coccicheck b/scripts/coccicheck > > index e04d328210ac..dd228dcc915e 100755 > > --- a/scripts/coccicheck > > +++ b/scripts/coccicheck > > @@ -75,8 +75,17 @@ else > > OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" > > fi > > > > + # Use only one thread per core by default if hyperthreading is > enabled > > + THREADS_PER_CORE=$(lscpu | grep "Thread(s) per core: " | tr -cd > [:digit:]) > > if [ -z "$J" ]; then > > NPROC=$(getconf _NPROCESSORS_ONLN) > > + if [ $THREADS_PER_CORE -gt 1 -a $NPROC -gt 2 ] ; then > > + if [ $NPROC -gt 8 ] ; then > > + NPROC=$((NPROC/4)) > > + else > > + NPROC=$((NPROC/2)) > > + fi > > + fi > > else > > NPROC="$J" > > fi > > -- > > 2.17.1 > > > > ___ > > Cocci mailing list > > Cocci@systeme.lip6.fr > > https://systeme.lip6.fr/mailman/listinfo/cocci > > > > >___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH] scripts: coccicheck: Change default value for parallelism
On Thu, 13 Aug, 2020, 1:45 AM Julia Lawall, wrote: > > > On Wed, 12 Aug 2020, Sumera Priyadarsini wrote: > > > By default, coccicheck utilizes all available threads to implement > > parallelisation. However, when hyperthreading is enabled, this leads > > to all threads per core being occupied resulting in longer wall-clock > > times and higher power consumption. > > I have the feeling that the above sentence is not quite optimal. > Actually, using all of the available hardware threads would not be a bad > thing, if it was giving a benefit. The point is that it doesn't. It > makes the performance worse instead. > How does this sound? However, when all available threads are used, a decrease in performance was noted. The elapsed time was minimum when at most one thread per core was used. > > Hence, to improve performance, > > modify coccicheck to use only one thread per core atmost. > > "atmost" is not a word. It would be clearer to say "to use at most one > thread per core". > > > In the cases where the total number of threads is more than 8 and > > hyperthreading is enabled, it was observed that optimum performance > > is achieved around one-fourth of the total number of cores. > > Modify the script further to accommodate this use case. > > It would be nice to give some performance numbers and some information > about the machine used. > Alright, will add this. > thanks, > julia > > > > > Signed-off-by: Sumera Priyadarsini > > --- > > scripts/coccicheck | 9 + > > 1 file changed, 9 insertions(+) > > > > diff --git a/scripts/coccicheck b/scripts/coccicheck > > index e04d328210ac..dd228dcc915e 100755 > > --- a/scripts/coccicheck > > +++ b/scripts/coccicheck > > @@ -75,8 +75,17 @@ else > > OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" > > fi > > > > +# Use only one thread per core by default if hyperthreading is > enabled > > +THREADS_PER_CORE=$(lscpu | grep "Thread(s) per core: " | tr -cd > [:digit:]) > > if [ -z "$J" ]; then > > NPROC=$(getconf _NPROCESSORS_ONLN) > > + if [ $THREADS_PER_CORE -gt 1 -a $NPROC -gt 2 ] ; then > > + if [ $NPROC -gt 8 ] ; then > > + NPROC=$((NPROC/4)) > > + else > > + NPROC=$((NPROC/2)) > > + fi > > + fi > > else > > NPROC="$J" > > fi > > -- > > 2.17.1 > > > > ___ > > Cocci mailing list > > Cocci@systeme.lip6.fr > > https://systeme.lip6.fr/mailman/listinfo/cocci > > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci