Embajada británica convoca altos mandos militares argentinos a una reunión secreta
Embajada británica convoca altos mandos militares argentinos a una reunión secreta
As it happens, we still use CVS in our operating system project (there are reasons for doing this, but migration to git would indeed make sense).
While working on our project, we occasionally have to do a full checkout of the whole codebase, which is several gigabytes. Over time, this operation has gotten very, very, very slow - I mean "2+ hours to perform a checkout" slow.
This was getting quite ridiculous. Even though it's CVS, it shouldn't crawl like this. A quick build of CVS with debug symbols and sampling the "cvs server" process with Linux perf showed something peculiar: The code was spending the majority of the time inside one function.
So what is this get_memnode() function? Turns out this is a support function from Gnulib that enables page-aligned memory allocations. (NOTE: I have no clue why CVS thinks doing page-aligned allocations is beneficial here - but here we are.)
The code in question has support for three different backend allocators:
1. mmap
2. posix_memalign
3. malloc
Sounds nice, except that both 1 and 3 use a linked list to track the allocations. The get_memnode() function is called when deallocating memory to find out the original pointer to pass to the backend deallocation function: The node search code appears as:
for (c = *p_next; c != NULL; p_next = &c->next, c = c->next)
if (c->aligned_ptr == aligned_ptr)
break;
The get_memnode() function is called from pagealign_free():
#if HAVE_MMAP
if (munmap (aligned_ptr, get_memnode (aligned_ptr)) < 0)
error (EXIT_FAILURE, errno, "Failed to unmap memory");
#elif HAVE_POSIX_MEMALIGN
free (aligned_ptr);
#else
free (get_memnode (aligned_ptr));
#endif
This is an O(n) operation. CVS must be allocating a huge number of small allocations, which will result in it spending most of the CPU time in get_memnode() trying to find the node to remove from the list.
Why should we care? This is "just CVS" after all. Well, Gnulib is used in a lot of projects, not just CVS. While pagealign_alloc() is likely not the most used functionality, it can still end up hurting performance in many places.
The obvious easy fix is to prefer the posix_memalign method over the other options (I quickly made this happen for my personal CVS build by adding tactical #undef HAVE_MMAP). Even better, the list code should be replaced with something more sensible. In fact, there is no need to store the original pointer in a list; a better solution is to allocate enough memory and store the pointer before the calculated aligned pointer. This way, the original pointer can be fetched from the negative offset of the pointer passed to pagealign_free(). This way, it will be O(1).
I tried to report this to the Gnulib project, but I have trouble reaching gnu.org services currently. I'll be sure to do that once things recover.
I'd track a stack of control-flow preprocessor lines tracking whether to keep or discard the lines between them, inserting #line where needed. This is how I'd handle #if, #elif, #else, #endif, #ifdef, #ifndef, #elifdef, #elifndef.
Some of these take identifiers whose presence it should check in the macros table, others would interpret infix expressions via a couple stacks & The Shunting Yard Algorithm. Or they simply end a control-flow block.
#undef removes an entry from the macros table.
3/4
Weekly GCC update:
Optimization improvements:
* Copy prop for aggregates improvements; now into args
* Recongize integer zero as zeroing for memset into aggregate copy or memcpy
* Improve VN support over aggregates copies
* Recongize saturation multiple more
* Allow for more mergeable constants to be placed in the mergeable section
C++ improvements/changes:
* Implement C++20 (Defect report) P1766R1: Mitigating minor modules maladies
* Fix parsing of non-comma variadic methods with default args
* Warn on #undef/#define cpp.predefined macros
* Implement C++26 P1306R5 - Expansion statements
* Implement P2036R3 - Change scope of lambda trailing-return-type
* Finish up P2115R0 implementation (unnamed unscoped enums)
Target changes:
* epiphany and rl78 are marked as obsolete targets
* LoongArch: 128bit atomics support
* LoongArch: _BitInt support
* x86: Add target("80387") function attribute
* RISCV: Add MIPS prefetch extensions
* aarch64: Fix CMPBR extension
So now I have a bunch of this in my code
#undef EXCEPTION_HANDLER
#define EXCEPTION_HANDLER myhandler
Then a block of code followed by
#undef EXCEPTION_HANDLER
#define EXCEPTION_HANDLER default_exception_handler
Is it jank? Yes, extremely. Does it do what I need it to do? Also yes. Do I feel embarrassed about this in any way? Not at all
Ughhh, autotools....
Not naming the project here.. Why would you assume that malloc and realloc are both broken just because you're cross compiling? Are you just being lazy? Even worse, don't '#undef malloc' and replace it with your own *broken* version.
Better yet, just don't even use autotools at all.
/*
* The sys_call_table[] is no longer used for system calls, but
* kernel/trace/trace_syscalls.c still wants to know the system
* call address.
*/
#define __SYSCALL(nr, sym) __x64_##sym,
const sys_call_ptr_t sys_call_table[] = {
#include <asm/syscalls_64.h>
};
#undef __SYSCALL
#define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs);
long x64_sys_call(const struct pt_regs *regs, unsigned int nr)
{
switch (nr) {
#include <asm/syscalls_64.h>
default: return __x64_sys_ni_syscall(regs);
}
}
:neobot_glare_sob:
silly little thing i made to debug that heisenbug
collecting all the things that i want to log and printing them after the fact, this avoids the overhead of printing immediately that seeming skewed the timing enough to make the bug disappear
there is one logger for every relevant thread, because synchronizing the logging would have also skewed the result obviously
struct microlog_entry
{
LONGLONG perf;
const char *text;
};
#define MICROLOGGER_CAP 100
struct micrologger
{
size_t pos;
size_t read_pos;
struct microlog_entry entries[MICROLOGGER_CAP];
};
#define microlog(l, text) if (l.pos < MICROLOGGER_CAP) { \
LARGE_INTEGER perf; \
QueryPerformanceCounter(&perf); \
l.entries[l.pos++] = (struct microlog_entry) { perf.QuadPart, text }; \
}
static struct micrologger l_grabber_events;
static struct micrologger l_grabber_samples;
static struct micrologger l_main;
void microlog_flush()
{
#define NUM_MICROLOGGERS 3
struct micrologger *loggers[NUM_MICROLOGGERS] = { &l_grabber_events, &l_grabber_samples, &l_main };
for (;;) {
struct micrologger *least = NULL;
for (size_t i = 0; i < NUM_MICROLOGGERS; i++) {
if (loggers[i]->read_pos == loggers[i]->pos)
continue;
if (!least || loggers[i]->entries[loggers[i]->read_pos].perf < least->entries[least->read_pos].perf)
least = loggers[i];
}
if (!least)
break;
printf("%s\n", least->entries[least->read_pos].text);
least->read_pos++;
}
#undef NUM_MICROLOGGERS
}
How to politely use assert in a header (gcc/clang/msvc/what else?):
#pragma push_macro("NDEBUG")
#undef NDEBUG
#include <assert.h>
// your asserts should properly assert
#pragma pop_macro("NDEBUG")
// nobody has 2 know
Your vendor’s assert.h should be able to be included multiple times with NDEBUG defined or not.
@kirakira did you know that you can define structured data in the c preprocessor using church encoding?
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#define USERS(_user) \
_user("sjolsen", "tech.lgbt"), \
_user("kirakira", "furry.engineer"), \
_user("Gargron", "mastodon.social")
#define handles_user(_name, _instance) "@" _name "@" _instance
static const char *const handles[] = {
USERS(handles_user)
};
#undef handles_user
#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a[0]))
int main() {
for (size_t i = 0; i < ARRAY_SIZE(handles); ++i) {
puts(handles[i]);
}
return EXIT_SUCCESS;
}
#undef HAS_GAMES
Mask Quest review: the cops don't have to breathe - https://www.rockpapershotgun.com/mask-quest-review #Platformer #WotIThink #Increpare #MaskQuest #Indie #undef #PC
@icculus I love SDL and have been using it for more than a decade, but the way they treat `main` always bothered me (`#define main SDL_main` is already obnoxious, and the actual main being implemented in a standalone shared lib is extra spicy). I always just did `#undef main` and took control from SDL on this.
Now they're making this thing even more integral and this makes me sad :(
(yes you can at least disable it with a special macro, but this being the default really bothers me)
gosh> (print "a")
a
#undef
なんでシンボルかと思っても文字列だぞ。気を付けろ!(俺がな)
Discover how conditional compilation directives can enhance your C programming skills. Learn to use #ifdef, #ifndef, #undef, #if, #else, #elif, and #endif to create more flexible and efficient code. Unlock the power of the C preprocessor!
https://teguhteja.id/conditional-compilation-directives-unlock-c-preprocessor-power/