linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] tools/libs/slab.c: fix compiling mistakes of uatomic_inc/uatomic_dec
@ 2022-08-29  6:38 Song Chen
  2022-08-29  7:11 ` Huang, Shaoqin
  2022-08-29  8:23 ` Mike Rapoport
  0 siblings, 2 replies; 3+ messages in thread
From: Song Chen @ 2022-08-29  6:38 UTC (permalink / raw)
  To: karolinadrobnik, rppt; +Cc: linux-kernel, linux-mm, Song Chen

I tried to build tools/test/memblock and got such message:

/usr/bin/ld: slab.o: in function `kmalloc':
slab.c:(.text+0x2b): undefined reference to `uatomic_inc'
/usr/bin/ld: slab.o: in function `kfree':
slab.c:(.text+0x97): undefined reference to `uatomic_dec'
collect2: error: ld returned 1 exit status

I could find any definition or inplememtation of uatomic_inc/uatomic_dec
in anywhere of the code base. So I use atomic_inc/atomic_dec_and_test
to replace like other tests underneath tools/test, it works.

Signed-off-by: Song Chen <chensong_2000@189.cn>
---
 tools/lib/slab.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/slab.c b/tools/lib/slab.c
index 959997fb0652..8a5a8d536e35 100644
--- a/tools/lib/slab.c
+++ b/tools/lib/slab.c
@@ -3,7 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <urcu/uatomic.h>
+#include <linux/atomic.h>
 #include <linux/slab.h>
 #include <malloc.h>
 #include <linux/gfp.h>
@@ -19,7 +19,7 @@ void *kmalloc(size_t size, gfp_t gfp)
 		return NULL;
 
 	ret = malloc(size);
-	uatomic_inc(&kmalloc_nr_allocated);
+	atomic_inc(&kmalloc_nr_allocated);
 	if (kmalloc_verbose)
 		printf("Allocating %p from malloc\n", ret);
 	if (gfp & __GFP_ZERO)
@@ -31,7 +31,7 @@ void kfree(void *p)
 {
 	if (!p)
 		return;
-	uatomic_dec(&kmalloc_nr_allocated);
+	atomic_dec_and_test(&kmalloc_nr_allocated);
 	if (kmalloc_verbose)
 		printf("Freeing %p to malloc\n", p);
 	free(p);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] tools/libs/slab.c: fix compiling mistakes of uatomic_inc/uatomic_dec
  2022-08-29  6:38 [PATCH 1/2] tools/libs/slab.c: fix compiling mistakes of uatomic_inc/uatomic_dec Song Chen
@ 2022-08-29  7:11 ` Huang, Shaoqin
  2022-08-29  8:23 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Huang, Shaoqin @ 2022-08-29  7:11 UTC (permalink / raw)
  To: Song Chen, karolinadrobnik, rppt; +Cc: linux-kernel, linux-mm

Hi, your two patches are not in one thread. Don't send it separately, 
Please send it together. Or others can't download your all patches from 
this message-id.

On 8/29/2022 2:38 PM, Song Chen wrote:
> I tried to build tools/test/memblock and got such message:
> 
> /usr/bin/ld: slab.o: in function `kmalloc':
> slab.c:(.text+0x2b): undefined reference to `uatomic_inc'
> /usr/bin/ld: slab.o: in function `kfree':
> slab.c:(.text+0x97): undefined reference to `uatomic_dec'
> collect2: error: ld returned 1 exit status
> 
> I could find any definition or inplememtation of uatomic_inc/uatomic_dec
> in anywhere of the code base. So I use atomic_inc/atomic_dec_and_test
> to replace like other tests underneath tools/test, it works.
> 
> Signed-off-by: Song Chen <chensong_2000@189.cn>
> ---
>   tools/lib/slab.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/lib/slab.c b/tools/lib/slab.c
> index 959997fb0652..8a5a8d536e35 100644
> --- a/tools/lib/slab.c
> +++ b/tools/lib/slab.c
> @@ -3,7 +3,7 @@
>   #include <stdio.h>
>   #include <string.h>
>   
> -#include <urcu/uatomic.h>
> +#include <linux/atomic.h>
>   #include <linux/slab.h>
>   #include <malloc.h>
>   #include <linux/gfp.h>
> @@ -19,7 +19,7 @@ void *kmalloc(size_t size, gfp_t gfp)
>   		return NULL;
>   
>   	ret = malloc(size);
> -	uatomic_inc(&kmalloc_nr_allocated);
> +	atomic_inc(&kmalloc_nr_allocated);
>   	if (kmalloc_verbose)
>   		printf("Allocating %p from malloc\n", ret);
>   	if (gfp & __GFP_ZERO)
> @@ -31,7 +31,7 @@ void kfree(void *p)
>   {
>   	if (!p)
>   		return;
> -	uatomic_dec(&kmalloc_nr_allocated);
> +	atomic_dec_and_test(&kmalloc_nr_allocated);
>   	if (kmalloc_verbose)
>   		printf("Freeing %p to malloc\n", p);
>   	free(p);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] tools/libs/slab.c: fix compiling mistakes of uatomic_inc/uatomic_dec
  2022-08-29  6:38 [PATCH 1/2] tools/libs/slab.c: fix compiling mistakes of uatomic_inc/uatomic_dec Song Chen
  2022-08-29  7:11 ` Huang, Shaoqin
@ 2022-08-29  8:23 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2022-08-29  8:23 UTC (permalink / raw)
  To: Song Chen; +Cc: karolinadrobnik, linux-kernel, linux-mm

On Mon, Aug 29, 2022 at 02:38:41PM +0800, Song Chen wrote:
> I tried to build tools/test/memblock and got such message:
> 
> /usr/bin/ld: slab.o: in function `kmalloc':
> slab.c:(.text+0x2b): undefined reference to `uatomic_inc'
> /usr/bin/ld: slab.o: in function `kfree':
> slab.c:(.text+0x97): undefined reference to `uatomic_dec'
> collect2: error: ld returned 1 exit status
> 
> I could find any definition or inplememtation of uatomic_inc/uatomic_dec
> in anywhere of the code base. So I use atomic_inc/atomic_dec_and_test
> to replace like other tests underneath tools/test, it works.

They are defined in liburcu headers, in Debian they are found in
liburcu-dev package.
 
> Signed-off-by: Song Chen <chensong_2000@189.cn>
> ---

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-29  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29  6:38 [PATCH 1/2] tools/libs/slab.c: fix compiling mistakes of uatomic_inc/uatomic_dec Song Chen
2022-08-29  7:11 ` Huang, Shaoqin
2022-08-29  8:23 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).