From b144cfcdbe95cc0a754cc414b70d5a21586009de Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Tue, 20 May 2025 19:43:47 +0300 Subject: [PATCH] Align structures 8 byte for 64-bit platforms references: - https://hpc.rz.rptu.de/Tutorials/AVX/alignment.shtml - https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-presentation.pdf - https://en.wikipedia.org/wiki/Data_structure_alignment - https://stackoverflow.com/a/20882083 - https://zijishi.xyz/post/optimization-technique/learning-to-use-data-alignment/ affected structs: - ScreenManager 72 to 64 bytes - Screen/DynamicIterator 24 to 16 bytes - Meter/DynamicIterator 24 to 16 bytes - IncMode 152 to 144 bytes - TraceScreen 64 to 56 bytes - LinuxProcessTable 120 to 112 bytes - FunctionBar 40 to 32 bytes Co-authored-by: BenBE --- DynamicMeter.c | 2 +- DynamicScreen.c | 2 +- FunctionBar.h | 4 ++-- IncSet.h | 2 +- ScreenManager.h | 4 ++-- TraceScreen.h | 4 ++-- linux/LinuxProcessTable.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DynamicMeter.c b/DynamicMeter.c index 1502bba9a..0492df413 100644 --- a/DynamicMeter.c +++ b/DynamicMeter.c @@ -48,8 +48,8 @@ void DynamicMeters_delete(Hashtable* dynamics) { } typedef struct { - ht_key_t key; const char* name; + ht_key_t key; bool found; } DynamicIterator; diff --git a/DynamicScreen.c b/DynamicScreen.c index 9e3d5e496..744fbf113 100644 --- a/DynamicScreen.c +++ b/DynamicScreen.c @@ -39,8 +39,8 @@ void DynamicScreen_done(DynamicScreen* this) { } typedef struct { - ht_key_t key; const char* name; + ht_key_t key; bool found; } DynamicIterator; diff --git a/FunctionBar.h b/FunctionBar.h index 06d9c6c8c..0715e4fd5 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -11,14 +11,14 @@ in the source distribution for its full text. typedef struct FunctionBar_ { - int size; + uint32_t size; + bool staticData; char** functions; union { char** keys; const char* const* constKeys; } keys; int* events; - bool staticData; } FunctionBar; #define FUNCTIONBAR_MAXEVENTS 15 diff --git a/IncSet.h b/IncSet.h index 28ecc6772..9da8dafa6 100644 --- a/IncSet.h +++ b/IncSet.h @@ -24,8 +24,8 @@ typedef enum { typedef struct IncMode_ { char buffer[INCMODE_MAX + 1]; - size_t index; FunctionBar* bar; + uint32_t index; bool isFilter; } IncMode; diff --git a/ScreenManager.h b/ScreenManager.h index 37821bb4f..c0cc67ab8 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -21,13 +21,13 @@ typedef struct ScreenManager_ { int y1; int x2; int y2; + bool allowFocusChange; + uint32_t panelCount; Vector* panels; const char* name; - int panelCount; Header* header; Machine* host; State* state; - bool allowFocusChange; } ScreenManager; ScreenManager* ScreenManager_new(Header* header, Machine* host, State* state, bool owner); diff --git a/TraceScreen.h b/TraceScreen.h index c0205839e..6c49003d8 100644 --- a/TraceScreen.h +++ b/TraceScreen.h @@ -18,9 +18,9 @@ in the source distribution for its full text. typedef struct TraceScreen_ { InfoScreen super; - bool tracing; - pid_t child; FILE* strace; + pid_t child; + bool tracing; bool contLine; bool follow; bool strace_alive; diff --git a/linux/LinuxProcessTable.h b/linux/LinuxProcessTable.h index b87f9b0a8..0a354eb1b 100644 --- a/linux/LinuxProcessTable.h +++ b/linux/LinuxProcessTable.h @@ -27,8 +27,8 @@ typedef struct LinuxProcessTable_ { bool haveAutogroup; #ifdef HAVE_DELAYACCT - struct nl_sock* netlink_socket; int netlink_family; + struct nl_sock* netlink_socket; #endif } LinuxProcessTable;