From: Maria Matejka Date: Tue, 10 Dec 2024 22:57:59 +0000 (+0100) Subject: Merge commit '4dd5b3d9' into thread-next X-Git-Tag: v3.0.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa5923289ed7429af75708595b7b2c92473d030b;p=thirdparty%2Fbird.git Merge commit '4dd5b3d9' into thread-next --- fa5923289ed7429af75708595b7b2c92473d030b diff --cc lib/birdlib.h index 57149cc93,4fea3f9f0..41aa8b3f0 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@@ -9,50 -9,17 +9,52 @@@ #ifndef _BIRD_BIRDLIB_H_ #define _BIRD_BIRDLIB_H_ +#include +#include + +#include "sysdep/config.h" #include "lib/alloca.h" +#include "lib/macro.h" + + #include + /* Ugly structure offset handling macros */ -struct align_probe { char x; long int y; }; +#define SAME_TYPE(a, b) ({ int _ = ((a) != (b)); !_; }) +#define TYPE_CAST(from, to, what) ( SAME_TYPE(((from) NULL), (what)), ((to) (what))) +#ifdef offsetof +#define OFFSETOF offsetof +#else #define OFFSETOF(s, i) ((size_t) &((s *)0)->i) -#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) +#endif + +#define SKIP_BACK(s, i, p) ({ \ + typeof(p) _orig = p; \ + s *_ptr = ((s *)((char *)_orig - OFFSETOF(s, i))); \ + SAME_TYPE(&_ptr->i, _orig); \ + _ptr; }) +#define SKIP_BACK_DECLARE(s, n, i, p) s *n = SKIP_BACK(s, i, p) #define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1)) -#define CPU_STRUCT_ALIGN (sizeof(struct align_probe)) +#define BIRD_SET_ALIGNED_POINTER(ptr, val) do { \ + size_t _alignment = _Alignof(typeof(*ptr)); \ + ptr = (typeof(ptr)) BIRD_ALIGN((uintptr_t)(val), _alignment); \ +} while (0) +#define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64))) +#define BIRD_CPU_ALIGN(s) BIRD_ALIGN((s), CPU_STRUCT_ALIGN) + +/* Structure item alignment macros */ + +#define PADDING_NAME(id) _padding_##id +#define PADDING_(id, sz) u8 PADDING_NAME(id)[sz] + +#if CPU_POINTER_ALIGNMENT == 4 +#define PADDING(id, n32, n64) PADDING_(id, n32) +#elif CPU_POINTER_ALIGNMENT == 8 +#define PADDING(id, n32, n64) PADDING_(id, n64) +#else +#error "Strange CPU pointer alignment: " CPU_POINTER_ALIGNMENT +#endif /* Utility macros */ diff --cc sysdep/unix/log.c index 9d77211bf,6c7cac540..384da303d --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@@ -282,73 -274,13 +282,73 @@@ log_commit(log_buffer *buf int buffer_vprint(buffer *buf, const char *fmt, va_list args); +void +log_prepare(log_buffer *buf, int class) +{ + buf->class = class; + + buf->buf.start = buf->buf.pos = buf->block; + buf->buf.end = buf->block + sizeof buf->block; + + int lf = atomic_load_explicit(&logging_flags, memory_order_acquire); + + buf->pos[LBP_TIMESTAMP] = buf->buf.pos; + if (BIT32_TEST(&lf, LBP_TIMESTAMP)) + { + rcu_read_lock(); + const char *fmt = atomic_load_explicit(&global_runtime, memory_order_acquire)->tf_log.fmt1; + int t = tm_format_real_time(buf->buf.pos, buf->buf.end - buf->buf.pos, fmt, current_real_time()); + rcu_read_unlock(); + if (t) + buf->buf.pos += t; + else + buffer_puts(&buf->buf, "