Skip to contentSkip to conversation

Problem with sizeof?

DISCUSSION Muthukumar Ratty 2 participants 3 messages Jul 8, 2002 1 message not in the archive MIPS

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 3 lines

I am not sure, but can this be memory allignment problem ?
you can check this by adding one more (dummy ) element of __u32 length (MIPS should print 40 insted of 44 and pc shuld print 40 as expected )

You are right. when I add a __u32 dummy to the tc_stats then it still prints the size as 40. Is it get padded at the end? My main concern is, is this a normal behavior or do I need to upgrade my MIPS build environment?
Thanks a lot,
Muthu.

Quoted 51 lines

if it works then you can get rid of the above problem by changing the compilar settings.

Regards,
venkatesh M R

Quoted 38 lines · Muthukumar Ratty

Hi,
In my MIPS system sizeof(struct tc_stats) returns 40 but it returns 36 in i386 PC.

tc_stats is defined in include/linux/pkt_sched.c as struct tc_stats
{

        __u64   bytes;                  /* NUmber of enqueues bytes */
        __u32   packets;                /* Number of enqueued packets   */
        __u32   drops;                  /* Packets dropped because of lack

of resources */
__u32 overlimits; /* Number of throttle events when
this
* flow goes out of allocated
bandwidth*/

        __u32   bps;                    /* Current flow byte rate */
        __u32   pps;                    /* Current flow packet rate */
        __u32   qlen;
        __u32   backlog;
#ifdef __KERNEL__
        spinlock_t *lock;

#endif
};
I printed the offsets of individual fields and they are same in i386 and MIPS. If the "spinlock_t" is defined then this may be the case but I am compiling an application, so it shouldnt be there? Right now I think the problem could be with the "sizeof" operator.
Could someone please let me know if this is the case or I am doing something wrong. Also any solution.

The versions are
kernel : 2.4.3
gcc : gcc version 3.1
binutils : 2.11.93
glibc : 2.2.5

Thanks,
Muthu.

#2 lore raw
Quoted 8 lines · Muthukumar Ratty
Quoted 3 lines

I am not sure, but can this be memory allignment problem ?
you can check this by adding one more (dummy ) element of __u32 length (MIPS should print 40 insted of 44 and pc shuld print 40 as expected )

You are right. when I add a __u32 dummy to the tc_stats then it still prints the size as 40. Is it get padded at the end? My main concern is, is this a normal behavior or do I need to upgrade my MIPS build environment?

The alignment rule for 64-bit value is 8 bytes on MIPS, and only 4 bytes on ia32.

Since sizeof(struct ...) must return a value that's a multiple of the alignment rule for the largest element in the struct, it returns 40 on MIPS.

Quoted 44 lines

Thanks a lot,
Muthu.

Quoted 41 lines

if it works then you can get rid of the above problem by changing the compilar settings.

Regards,
venkatesh M R

Quoted 29 lines · Muthukumar Ratty

Hi,
In my MIPS system sizeof(struct tc_stats) returns 40 but it returns 36 in i386 PC.

tc_stats is defined in include/linux/pkt_sched.c as struct tc_stats
{

        __u64   bytes;                  /* NUmber of enqueues bytes */
        __u32   packets;                /* Number of enqueued packets   */
        __u32   drops;                  /* Packets dropped because of lack

of resources */
__u32 overlimits; /* Number of throttle events when
this
* flow goes out of allocated
bandwidth*/

        __u32   bps;                    /* Current flow byte rate */
        __u32   pps;                    /* Current flow packet rate */
        __u32   qlen;
        __u32   backlog;
#ifdef __KERNEL__
        spinlock_t *lock;

#endif
};
I printed the offsets of individual fields and they are same in i386 and MIPS. If the "spinlock_t" is defined then this may be the case but I am compiling an application, so it shouldnt be there? Right now I think the problem could be with the "sizeof" operator.
Could someone please let me know if this is the case or I am doing something wrong. Also any solution.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw

Hi Geert,
The main reason I thought my environment could be broken is because I got the problem with iproute2 by Alexey!! Anyway I sent a mail to Alexey to check with him.
Thanks,
Muthu

Quoted 72 lines · Geert Uytterhoeven
Quoted 8 lines · Muthukumar Ratty
Quoted 3 lines

I am not sure, but can this be memory allignment problem ?
you can check this by adding one more (dummy ) element of __u32 length (MIPS should print 40 insted of 44 and pc shuld print 40 as expected )

You are right. when I add a __u32 dummy to the tc_stats then it still prints the size as 40. Is it get padded at the end? My main concern is, is this a normal behavior or do I need to upgrade my MIPS build environment?

The alignment rule for 64-bit value is 8 bytes on MIPS, and only 4 bytes on ia32.

Since sizeof(struct ...) must return a value that's a multiple of the alignment rule for the largest element in the struct, it returns 40 on MIPS.

Quoted 44 lines

Thanks a lot,
Muthu.

Quoted 41 lines

if it works then you can get rid of the above problem by changing the compilar settings.

Regards,
venkatesh M R

Quoted 29 lines · Muthukumar Ratty

Hi,
In my MIPS system sizeof(struct tc_stats) returns 40 but it returns 36 in i386 PC.

tc_stats is defined in include/linux/pkt_sched.c as struct tc_stats
{

        __u64   bytes;                  /* NUmber of enqueues bytes */
        __u32   packets;                /* Number of enqueued packets   */
        __u32   drops;                  /* Packets dropped because of lack

of resources */
__u32 overlimits; /* Number of throttle events when
this
* flow goes out of allocated
bandwidth*/

        __u32   bps;                    /* Current flow byte rate */
        __u32   pps;                    /* Current flow packet rate */
        __u32   qlen;
        __u32   backlog;
#ifdef __KERNEL__
        spinlock_t *lock;

#endif
};
I printed the offsets of individual fields and they are same in i386 and MIPS. If the "spinlock_t" is defined then this may be the case but I am compiling an application, so it shouldnt be there? Right now I think the problem could be with the "sizeof" operator.
Could someone please let me know if this is the case or I am doing something wrong. Also any solution.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds