Changeset View
Standalone View
sys/net/vnet.h
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
#if defined(_KERNEL) || defined(_WANT_VNET) | #if defined(_KERNEL) || defined(_WANT_VNET) | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
struct vnet { | struct vnet { | ||||
LIST_ENTRY(vnet) vnet_le; /* all vnets list */ | LIST_ENTRY(vnet) vnet_le; /* all vnets list */ | ||||
u_int vnet_magic_n; | u_int vnet_magic_n; | ||||
u_int vnet_ifcnt; | u_int vnet_ifcnt; | ||||
u_int vnet_sockcnt; | u_int vnet_sockcnt; | ||||
u_int vnet_shutdown; /* Shutdown in progress. */ | u_int vnet_state; /* SI_SUB_* */ | ||||
void *vnet_data_mem; | void *vnet_data_mem; | ||||
uintptr_t vnet_data_base; | uintptr_t vnet_data_base; | ||||
}; | bool vnet_shutdown; /* Shutdown in progress. */ | ||||
#define VNET_MAGIC_N 0x3e0d8f29 | } __aligned(CACHE_LINE_SIZE); | ||||
hselasky: Is the size of bool always constant or should you use uint8_t ? | |||||
Done Inline ActionsYou mean for using a bit field? uint8_t vnet_shutdown:1; Is all the "spare" part for some alignment constraints? static_assert(xxx == sizeof(struct vnet), "ABI requires a fixed size of the structure"); Currently the "spare" part is fragmented and unused, can we use a simple padding instead? uint8_t _vnet_padding[xxx]; donner: You mean for using a bit field?
```
uint8_t vnet_shutdown:1;
```
Is all the "spare" part for… | |||||
Done Inline ActionsYes, if only for use with same architecture, bitfields are better in my opinion. Maybe: Pad it to something like a CACHE_LINE size. The __packed keyword may cause an overhead on ARM. Maybe better to use explicit __aligned() for all integer fields .... hselasky: Yes, if only for use with same architecture, bitfields are better in my opinion.
Maybe:
u_int… | |||||
Done Inline ActionsIf we want to use a bool for shutdown we should start treating it as a bool and write it as a bool; if we do a bitfield we'll do vnet_flags & VNET_FLAGS_SHUTDOWN and given we do bool in the kernel I see no reason anymore. The size of a bool is at least big enough to hold 1 or 0. generally sizeof(bool) seems to be 1 but it could be bigger. "spare" is a common name as a placeholder for padding; if you need to reserve something you give it a better name or a comment. It is to avoid implicit padding and the immediate need to change the size of the struct in the future for, say, other internal state. There is a problem however that on 32bit this might still be true given the sizeof(void *)... bz: If we want to use a bool for shutdown we should start treating it as a bool and write it as a… | |||||
#define VNET_MAGIC_N 0x5e31a7bd | |||||
/* | /* | ||||
Done Inline ActionsI think the __packed might not be needed. bz: I think the __packed might not be needed. | |||||
* These two virtual network stack allocator definitions are also required | * These two virtual network stack allocator definitions are also required | ||||
* for libkvm so that it can evaluate virtualized global variables. | * for libkvm so that it can evaluate virtualized global variables. | ||||
*/ | */ | ||||
#define VNET_SETNAME "set_vnet" | #define VNET_SETNAME "set_vnet" | ||||
#define VNET_SYMPREFIX "vnet_entry_" | #define VNET_SYMPREFIX "vnet_entry_" | ||||
#endif | #endif | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
▲ Show 20 Lines • Show All 366 Lines • Show Last 20 Lines |
Is the size of bool always constant or should you use uint8_t ?