Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/disco/events/fd_boot_report.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ cpuinfo_field( char const * cpuinfo,
return out;
}

static int
read_msr( uint cpu,
ulong msr,
ulong * value ) {
char path[ 64 ];
FD_TEST( fd_cstr_printf_check( path, sizeof(path), NULL, "/dev/cpu/%u/msr", cpu ) );
int fd = open( path, O_RDONLY|O_CLOEXEC );
if( FD_UNLIKELY( fd<0 ) ) return -1;
ulong tmp;
long n = pread( fd, &tmp, sizeof(tmp), (off_t)msr );
Comment thread
ripatel-fd marked this conversation as resolved.
close( fd );
if( FD_UNLIKELY( n!=(long)sizeof(tmp) ) ) return -1;
*value = tmp;
return 0;
}

static void
collect_cpu( fd_boot_report_t * r ) {
struct utsname un;
Expand Down Expand Up @@ -305,6 +321,16 @@ collect_cpu( fd_boot_report_t * r ) {
r->cpu_model_id = (ushort)( base_model | fd_uint_if( base_family==0x6U || base_family==0xFU, ext_model<<4, 0U ) );
r->cpu_stepping = (uchar)( eax&0xFU );
}

r->msr_x86_spec_ctrl_present = !read_msr( 0U, 0x00000048UL, &r->msr_x86_spec_ctrl );
if( r->cpu_vendor==2 ) { /* AMD specific */
r->msr_x86_amd_syscfg_present = !read_msr( 0U, 0xC0010010UL, &r->msr_x86_amd_syscfg );
r->msr_x86_amd_bp_cfg_present = !read_msr( 0U, 0xC001102EUL, &r->msr_x86_amd_bp_cfg );
r->msr_x86_amd_hwcr_present = !read_msr( 0U, 0xC0010015UL, &r->msr_x86_amd_hwcr );
r->msr_x86_amd_prefetch_ctl_present = !read_msr( 0U, 0xC0000108UL, &r->msr_x86_amd_prefetch_ctl );
r->msr_x86_amd_de_cfg_present = !read_msr( 0U, 0xC0011029UL, &r->msr_x86_amd_de_cfg );
r->msr_x86_amd_cppc_cap1_present = !read_msr( 0U, 0xC00102B0UL, &r->msr_x86_amd_cppc_cap1 );
}
# endif /* defined(__x86_64__) */

char cpuinfo[ 16384 ];
Expand Down Expand Up @@ -1512,6 +1538,13 @@ fd_boot_report_publish( fd_boot_report_t * r,
if( r->memory_normal_pages ) ok &= !!fd_pb_push_uint64( encoder, 73U, r->memory_normal_pages );
if( r->process_start_time_nanos ) ok &= !!fd_pb_push_uint64( encoder, 74U, r->process_start_time_nanos );
if( r->feature_set_id ) ok &= !!fd_pb_push_uint32( encoder, 75U, r->feature_set_id );
if( r->msr_x86_amd_syscfg_present ) ok &= !!fd_pb_push_uint64( encoder, 76U, r->msr_x86_amd_syscfg );
if( r->msr_x86_amd_bp_cfg_present ) ok &= !!fd_pb_push_uint64( encoder, 77U, r->msr_x86_amd_bp_cfg );
if( r->msr_x86_amd_hwcr_present ) ok &= !!fd_pb_push_uint64( encoder, 78U, r->msr_x86_amd_hwcr );
if( r->msr_x86_amd_prefetch_ctl_present ) ok &= !!fd_pb_push_uint64( encoder, 79U, r->msr_x86_amd_prefetch_ctl );
if( r->msr_x86_amd_de_cfg_present ) ok &= !!fd_pb_push_uint64( encoder, 80U, r->msr_x86_amd_de_cfg );
if( r->msr_x86_amd_cppc_cap1_present ) ok &= !!fd_pb_push_uint64( encoder, 81U, r->msr_x86_amd_cppc_cap1 );
if( r->msr_x86_spec_ctrl_present ) ok &= !!fd_pb_push_uint64( encoder, 82U, r->msr_x86_spec_ctrl );

ok &= !!fd_pb_submsg_close( encoder );
ok &= !!fd_pb_submsg_close( encoder );
Expand Down
18 changes: 18 additions & 0 deletions src/disco/events/fd_boot_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ struct fd_boot_report {
ulong memory_normal_pages;
ulong process_start_time_nanos;
uint feature_set_id;

/* Raw MSR values at boot time */

ulong msr_x86_amd_syscfg;
ulong msr_x86_amd_bp_cfg;
ulong msr_x86_amd_hwcr;
ulong msr_x86_amd_prefetch_ctl;
ulong msr_x86_amd_de_cfg;
ulong msr_x86_amd_cppc_cap1;
ulong msr_x86_spec_ctrl;

uint msr_x86_amd_syscfg_present : 1;
uint msr_x86_amd_bp_cfg_present : 1;
uint msr_x86_amd_hwcr_present : 1;
uint msr_x86_amd_prefetch_ctl_present : 1;
uint msr_x86_amd_de_cfg_present : 1;
uint msr_x86_amd_cppc_cap1_present : 1;
uint msr_x86_spec_ctrl_present : 1;
};
typedef struct fd_boot_report fd_boot_report_t;

Expand Down
15 changes: 14 additions & 1 deletion src/disco/events/gen_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class ClickHouseType(Enum):
UInt8 = auto()
UInt16 = auto()
UInt32 = auto()
NullableUInt32 = auto()
UInt64 = auto()
UInt128 = auto()
NullableUInt64 = auto()
Int64 = auto()
Pubkey = auto()
Hash = auto()
Expand All @@ -45,8 +47,10 @@ class ClickHouseType(Enum):
"UInt8": "UInt8",
"UInt16": "UInt16",
"UInt32": "UInt32",
"Nullable(UInt32)": "NullableUInt32",
"UInt64": "UInt64",
"UInt128": "UInt128",
"Nullable(UInt64)": "NullableUInt64",
"Int64": "Int64",
"Pubkey": "Pubkey",
"Hash": "Hash",
Expand All @@ -66,8 +70,10 @@ class ClickHouseType(Enum):
"UInt8": "uint32",
"UInt16": "uint32",
"UInt32": "uint32",
"NullableUInt32": "uint32",
"UInt64": "uint64",
"UInt128": "bytes",
"NullableUInt64": "uint64",
"Int64": "sint64",
"Pubkey": "bytes",
"Hash": "bytes",
Expand Down Expand Up @@ -190,7 +196,12 @@ def generate_message_fields(fields: Dict[str, Field], prefix: str = "") -> List[
proto_type = inner.shared_name or f"{prefix}{to_pascal_case(name)}"
else:
proto_type = inner.chtype.to_protobuf_type()
label = "repeated " if f.chtype == ClickHouseType.Array else ""
if f.chtype == ClickHouseType.Array:
label = "repeated "
elif f.chtype in (ClickHouseType.NullableUInt32, ClickHouseType.NullableUInt64):
label = "optional "
else:
label = ""
lines += [f" // {f.description}", f" {label}{proto_type} {name} = {i};"]

return lines
Expand Down Expand Up @@ -275,6 +286,8 @@ def field_is_supported(f: Field) -> bool:
_NON_LEAF = (ClickHouseType.String, ClickHouseType.Bytes,
ClickHouseType.Flatten, ClickHouseType.Tuple, ClickHouseType.Array)
_SUB_UNSUPPORTED = _NON_LEAF + (ClickHouseType.LowCardinalityString,)
if f.chtype in (ClickHouseType.NullableUInt32, ClickHouseType.NullableUInt64):
return False
if f.chtype == ClickHouseType.LowCardinalityString:
return f.variants is not None
if f.chtype in (ClickHouseType.String, ClickHouseType.Bytes):
Expand Down
Loading
Loading