diff mbox

[dpdk-dev,v4,10/17] malloc: fix the issue of SOCKET_ID_ANY

Message ID 1422842559-13617-11-git-send-email-cunming.liang@intel.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Cunming Liang Feb. 2, 2015, 2:02 a.m. UTC
Add check for rte_socket_id(), avoid get unexpected return like (-1).

Signed-off-by: Cunming Liang <cunming.liang@intel.com>
---
 lib/librte_malloc/malloc_heap.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Olivier Matz Feb. 8, 2015, 8 p.m. UTC | #1
Hi,

On 02/02/2015 03:02 AM, Cunming Liang wrote:
> Add check for rte_socket_id(), avoid get unexpected return like (-1).
> 
> Signed-off-by: Cunming Liang <cunming.liang@intel.com>
> ---
>  lib/librte_malloc/malloc_heap.h | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_malloc/malloc_heap.h b/lib/librte_malloc/malloc_heap.h
> index b4aec45..a47136d 100644
> --- a/lib/librte_malloc/malloc_heap.h
> +++ b/lib/librte_malloc/malloc_heap.h
> @@ -44,7 +44,12 @@ extern "C" {
>  static inline unsigned
>  malloc_get_numa_socket(void)
>  {
> -	return rte_socket_id();
> +	unsigned socket_id = rte_socket_id();
> +
> +	if (socket_id == (unsigned)SOCKET_ID_ANY)
> +		return 0;
> +
> +	return socket_id;
>  }
>  
>  void *
> 

The documentation off rte_malloc_socket() says:

@param socket
  NUMA socket to allocate memory on. If SOCKET_ID_ANY is used, this
  function will behave the same as rte_malloc().

void *
rte_malloc_socket(const char *type, size_t size, unsigned align, int
socket);


Your patch changes the behavior of rte_malloc() without explaining
why, and the documentation becomes wrong.

Can you explain why you need this change?

Regards,
Olivier
Cunming Liang Feb. 9, 2015, 2:08 p.m. UTC | #2
> -----Original Message-----
> From: Olivier MATZ [mailto:olivier.matz@6wind.com]
> Sent: Monday, February 09, 2015 4:01 AM
> To: Liang, Cunming; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v4 10/17] malloc: fix the issue of SOCKET_ID_ANY
> 
> Hi,
> 
> On 02/02/2015 03:02 AM, Cunming Liang wrote:
> > Add check for rte_socket_id(), avoid get unexpected return like (-1).
> >
> > Signed-off-by: Cunming Liang <cunming.liang@intel.com>
> > ---
> >  lib/librte_malloc/malloc_heap.h | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_malloc/malloc_heap.h b/lib/librte_malloc/malloc_heap.h
> > index b4aec45..a47136d 100644
> > --- a/lib/librte_malloc/malloc_heap.h
> > +++ b/lib/librte_malloc/malloc_heap.h
> > @@ -44,7 +44,12 @@ extern "C" {
> >  static inline unsigned
> >  malloc_get_numa_socket(void)
> >  {
> > -	return rte_socket_id();
> > +	unsigned socket_id = rte_socket_id();
> > +
> > +	if (socket_id == (unsigned)SOCKET_ID_ANY)
> > +		return 0;
> > +
> > +	return socket_id;
> >  }
> >
> >  void *
> >
> 
> The documentation off rte_malloc_socket() says:
> 
> @param socket
>   NUMA socket to allocate memory on. If SOCKET_ID_ANY is used, this
>   function will behave the same as rte_malloc().
> 
> void *
> rte_malloc_socket(const char *type, size_t size, unsigned align, int
> socket);
> 
> 
> Your patch changes the behavior of rte_malloc() without explaining
> why, and the documentation becomes wrong.
> 
> Can you explain why you need this change?
[LCM] I don't think I change the declaration of rte_malloc_socket().
If socket_arg=SOCKET_ID_ANY, the socket value expect to the return value of malloc_get_numa_socket().
The malloc_get_numa_socket() supposed to return the correct TLS _socket_id.
It works fine for normal cases. But as we change the default value of TLS _socket_id to SOCKET_ID_ANY.
And one lcore can run on multiple cpu, if all cpus in the cpuset are not belongs to one NUMA node, the _socket_id would be SOCKET_ID_ANY.
When user call rte_malloc_socket(SOCKET_ID_ANY), it does provide the same behavior as rte_malloc().
They both will get socket_id from malloc_get_numa_socket(). The addition part is the exception path process.
> 
> Regards,
> Olivier
Olivier Matz Feb. 9, 2015, 5:43 p.m. UTC | #3
Hi,

On 02/09/2015 03:08 PM, Liang, Cunming wrote:
> 
> 
>> -----Original Message-----
>> From: Olivier MATZ [mailto:olivier.matz@6wind.com]
>> Sent: Monday, February 09, 2015 4:01 AM
>> To: Liang, Cunming; dev@dpdk.org
>> Subject: Re: [dpdk-dev] [PATCH v4 10/17] malloc: fix the issue of SOCKET_ID_ANY
>>
>> Hi,
>>
>> On 02/02/2015 03:02 AM, Cunming Liang wrote:
>>> Add check for rte_socket_id(), avoid get unexpected return like (-1).
>>>
>>> Signed-off-by: Cunming Liang <cunming.liang@intel.com>
>>> ---
>>>  lib/librte_malloc/malloc_heap.h | 7 ++++++-
>>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/lib/librte_malloc/malloc_heap.h b/lib/librte_malloc/malloc_heap.h
>>> index b4aec45..a47136d 100644
>>> --- a/lib/librte_malloc/malloc_heap.h
>>> +++ b/lib/librte_malloc/malloc_heap.h
>>> @@ -44,7 +44,12 @@ extern "C" {
>>>  static inline unsigned
>>>  malloc_get_numa_socket(void)
>>>  {
>>> -	return rte_socket_id();
>>> +	unsigned socket_id = rte_socket_id();
>>> +
>>> +	if (socket_id == (unsigned)SOCKET_ID_ANY)
>>> +		return 0;
>>> +
>>> +	return socket_id;
>>>  }
>>>
>>>  void *
>>>
>>
>> The documentation off rte_malloc_socket() says:
>>
>> @param socket
>>   NUMA socket to allocate memory on. If SOCKET_ID_ANY is used, this
>>   function will behave the same as rte_malloc().
>>
>> void *
>> rte_malloc_socket(const char *type, size_t size, unsigned align, int
>> socket);
>>
>>
>> Your patch changes the behavior of rte_malloc() without explaining
>> why, and the documentation becomes wrong.
>>
>> Can you explain why you need this change?
> [LCM] I don't think I change the declaration of rte_malloc_socket().
> If socket_arg=SOCKET_ID_ANY, the socket value expect to the return value of malloc_get_numa_socket().
> The malloc_get_numa_socket() supposed to return the correct TLS _socket_id.
> It works fine for normal cases. But as we change the default value of TLS _socket_id to SOCKET_ID_ANY.
> And one lcore can run on multiple cpu, if all cpus in the cpuset are not belongs to one NUMA node, the _socket_id would be SOCKET_ID_ANY.
> When user call rte_malloc_socket(SOCKET_ID_ANY), it does provide the same behavior as rte_malloc().
> They both will get socket_id from malloc_get_numa_socket(). The addition part is the exception path process.

Sorry, I checked again, you are right.
diff mbox

Patch

diff --git a/lib/librte_malloc/malloc_heap.h b/lib/librte_malloc/malloc_heap.h
index b4aec45..a47136d 100644
--- a/lib/librte_malloc/malloc_heap.h
+++ b/lib/librte_malloc/malloc_heap.h
@@ -44,7 +44,12 @@  extern "C" {
 static inline unsigned
 malloc_get_numa_socket(void)
 {
-	return rte_socket_id();
+	unsigned socket_id = rte_socket_id();
+
+	if (socket_id == (unsigned)SOCKET_ID_ANY)
+		return 0;
+
+	return socket_id;
 }
 
 void *