tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Another kvm user can go away?
On Sat, 31 Dec 2016, Simon Burge wrote:
Paul Goyette wrote:
Any suggestions on how to ensure proper alignment? There doesn't seem
to be any way to kmem_allocate() what alignment is needed... :) It
seems to currently always provide 64-bit (8-byte) alignment, but the man
page makes no guarantees.
I guess I could allocate an extra 8 bytes, and then manipulate the
returned address... But that just "feels wrong". :)
I meant alignment within the structures. Maybe "packing" might be
a better word. This helps for example with mixed 32-bit and 64-bit
emulations. If you look at your original struct sysctl_history_event:
struct sysctl_history_event {
struct timeval she_tv;
uint64_t she_callnumber;
uint64_t she_values[4];
The timeval is a structure with a 64-bit int for seconds and and
a 32-bit int for microseconds. With the following uint64_t some
architectures might pad out she_callnumber in the structure so that it's
on a 64-bit boundary while others will by happy with a 32-bit alignment
and not use any padding.
In short, just make sure everything in the struct packs nicely. :)
Yeah, I figured that out after I replied (with the help of Christos's
suggestion. My latest revision uses a 'struct timespec' which has two
64-bit members, so preserves alignment of subsequent members!
+------------------+--------------------------+------------------------+
| Paul Goyette | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+
Home |
Main Index |
Thread Index |
Old Index