Skip to contentSkip to conversation

alloc_netdev() and 32 byte or 32 bit alignment???

KJ Eric Dumazet 3 participants 4 messages May 18, 2007 Kernel janitors

lore
Share & tools
lore
#0 lore raw
Quoted 20 lines · On Fri, 18 May 2007 17:10:02 +0530 "pradeep singh" <[email protected]>…

Hi ,

following code snippet is self evident in what it does -

truct net_device *alloc_netdev(int sizeof_priv, const char *name,
void (*setup)(struct net_device *))

{
	void *p;
	struct net_device *dev;
	int alloc_size;

	/* ensure 32-byte alignment of both the device and private area */
	alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
	alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;

	p = kzalloc(alloc_size, GFP_KERNEL);
	if (!p) {
		printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
		return NULL;
	}
Quoted 3 lines

[snip]

Is the comment correct?

yes it seems correct

Quoted 1 line

Why is it 'ensure 32 byte alignment', instead of 32 bit alignment?

Its 32 bytes, not bits.

#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)

Quoted 2 lines

What am i missing here?

I dont know :)

This 32 bytes alignement maybe not up2date, because net_device contains several ____cacheline_aligned_in_smp

Would be nice to switch the alignement to max(L1_CACHE_SIZE, 32) nowadays, at least on SMP

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 20 lines · pradeep singh

Hi ,

following code snippet is self evident in what it does -

truct net_device *alloc_netdev(int sizeof_priv, const char *name,
void (*setup)(struct net_device *))

{
	void *p;
	struct net_device *dev;
	int alloc_size;

	/* ensure 32-byte alignment of both the device and private area */
	alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
	alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;

	p = kzalloc(alloc_size, GFP_KERNEL);
	if (!p) {
		printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
		return NULL;
	}
Quoted 6 lines

[snip]

Is the comment correct?
Why is it 'ensure 32 byte alignment', instead of 32 bit alignment?

What am i missing here?

Google turned up following useful link:
http://www.nabble.com/-RFC--changing-value-of-NETDEV_ALIGN-to-cacheline-size-t1620499.html

snip:
The reason it's 32 is that old drivers depended on the struct being at least 32-byte aligned because they would embed structures DMA'd to/from the card in their private area and just assumed that would be aligned enough for the card's restrictions.

Sam
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#2 lore raw
In reply to Eric Dumazet
Quoted 37 lines · Eric Dumazet
Quoted 20 lines · On Fri, 18 May 2007 17:10:02 +0530 "pradeep singh" <[email protected]>…

Hi ,

following code snippet is self evident in what it does -

truct net_device *alloc_netdev(int sizeof_priv, const char *name,
void (*setup)(struct net_device *))

{
      void *p;
      struct net_device *dev;
      int alloc_size;

      /* ensure 32-byte alignment of both the device and private area */
      alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
      alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;

      p = kzalloc(alloc_size, GFP_KERNEL);
      if (!p) {
              printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
              return NULL;
      }
Quoted 3 lines

[snip]

Is the comment correct?

yes it seems correct

Quoted 1 line

Why is it 'ensure 32 byte alignment', instead of 32 bit alignment?

Its 32 bytes, not bits.

#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)

Quoted 1 line
Quoted 5 lines
Quoted 1 line

What am i missing here?

I dont know :)

This 32 bytes alignement maybe not up2date, because net_device contains several ____cacheline_aligned_in_smp

Thanks eric
got it.

--psr

Quoted 4 lines

Would be nice to switch the alignement to max(L1_CACHE_SIZE, 32) nowadays, at least on SMP

Signature · 5 lines
play the game
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors
#3 lore raw
In reply to Eric Dumazet
Quoted 23 lines · Sam Ravnborg
Quoted 22 lines · pradeep singh

Hi ,

following code snippet is self evident in what it does -

truct net_device *alloc_netdev(int sizeof_priv, const char *name,
void (*setup)(struct net_device *))

{
      void *p;
      struct net_device *dev;
      int alloc_size;

      /* ensure 32-byte alignment of both the device and private area */
      alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
      alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;

      p = kzalloc(alloc_size, GFP_KERNEL);
      if (!p) {
              printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
              return NULL;
      }

[snip]

Quoted 7 lines
Quoted 4 lines

Is the comment correct?
Why is it 'ensure 32 byte alignment', instead of 32 bit alignment?

What am i missing here?

Google turned up following useful link:
http://www.nabble.com/-RFC--changing-value-of-NETDEV_ALIGN-to-cacheline-size-t1620499.html

Thank you Sam.
This is really the answer i should have searched :-(.

A lesson to learn indeed.

Thank you once again.
--psr

Quoted 10 lines

snip:
The reason it's 32 is that old drivers depended on the struct being at least 32-byte aligned because they would embed structures DMA'd to/from the card in their private area and just assumed that would be aligned enough for the card's restrictions.

Sam

Signature · 5 lines
play the game
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors