mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[caffe2] Update tracepoint USDT macros (#105232)
Summary: Fix existing CAFFE static tracepoint macros and make them match the latest FOLLY version. Per anakryiko, current `CAFE_SDT` definition is broken. Quote: ``` "Arguments: -5@-16(%rbp) -4@$100 Arguments: -8@-16(%rbp) -4@$100 #define FOLLY_SDT_IS_ARRAY_POINTER(x) ((__builtin_classify_type(x) == 14) || \ (__builtin_classify_type(x) == 5)) vs #define CAFFE_SDT_ISARRAY(x) (__builtin_classify_type(x) == 14) https://github.com/atgreen/gcc/blob/master/gcc/typeclass.h that 5 is "pointer_type_class" so you were right, it's just fixed up version of header I think it should be 8, not 5 5 is the size of literal, but you don't pass string literal as an argument, you pass its address, so actual argument is a pointer, and so 8 byte long you can try just fixing up CAFFE_SDT macro ``` {F1048035373} Test Plan: Tested the following macros on test scripts with libbpf USDTs: CAFFE_SDT CAFFE_DISABLE_SDT CAFFE_SDT_WITH_SEMAPHORE Reviewed By: RihamSelim Differential Revision: D47159249 Pull Request resolved: https://github.com/pytorch/pytorch/pull/105232 Approved by: https://github.com/chaekit, https://github.com/malfet
This commit is contained in:
committed by
PyTorch MergeBot
parent
024d26208c
commit
e47fad68a0
@ -1,11 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(__ELF__) && (defined(__x86_64__) || defined(__i386__))
|
||||
#if defined(__ELF__) && (defined(__x86_64__) || defined(__i386__)) && !CAFFE_DISABLE_SDT
|
||||
|
||||
#define CAFFE_HAVE_SDT 1
|
||||
|
||||
#include <caffe2/core/static_tracepoint_elfx86.h>
|
||||
|
||||
#define CAFFE_SDT(name, ...) \
|
||||
CAFFE_SDT_PROBE_N( \
|
||||
caffe2, name, CAFFE_SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__)
|
||||
#define CAFFE_SDT(name, ...) \
|
||||
CAFFE_SDT_PROBE_N( \
|
||||
caffe2, name, 0, CAFFE_SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__)
|
||||
// Use CAFFE_SDT_DEFINE_SEMAPHORE(name) to define the semaphore
|
||||
// as global variable before using the CAFFE_SDT_WITH_SEMAPHORE macro
|
||||
#define CAFFE_SDT_WITH_SEMAPHORE(name, ...) \
|
||||
CAFFE_SDT_PROBE_N( \
|
||||
caffe2, name, 1, CAFFE_SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__)
|
||||
#define CAFFE_SDT_IS_ENABLED(name) \
|
||||
(CAFFE_SDT_SEMAPHORE(caffe2, name) > 0)
|
||||
|
||||
#else
|
||||
#define CAFFE_SDT(name, ...) do {} while(0)
|
||||
|
||||
#define CAFFE_HAVE_SDT 0
|
||||
|
||||
#define CAFFE_SDT(name, ...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#define CAFFE_SDT_WITH_SEMAPHORE(name, ...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#define CAFFE_SDT_IS_ENABLED(name) (false)
|
||||
#define CAFFE_SDT_DEFINE_SEMAPHORE(name)
|
||||
#define CAFFE_SDT_DECLARE_SEMAPHORE(name)
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// clang-format off
|
||||
#include <cstddef>
|
||||
|
||||
// Default constraint for the probe arguments as operands.
|
||||
#ifndef CAFFE_SDT_ARG_CONSTRAINT
|
||||
#define CAFFE_SDT_ARG_CONSTRAINT "nor"
|
||||
@ -12,6 +15,9 @@
|
||||
#define CAFFE_SDT_NOTE_NAME "stapsdt"
|
||||
#define CAFFE_SDT_NOTE_TYPE 3
|
||||
|
||||
// Semaphore variables are put in this section
|
||||
#define CAFFE_SDT_SEMAPHORE_SECTION ".probes"
|
||||
|
||||
// Size of address depending on platform.
|
||||
#ifdef __LP64__
|
||||
#define CAFFE_SDT_ASM_ADDR .8byte
|
||||
@ -28,8 +34,11 @@
|
||||
#define CAFFE_SDT_ASM_STRING(x) CAFFE_SDT_ASM_1(.asciz CAFFE_SDT_S(x))
|
||||
|
||||
// Helper to determine the size of an argument.
|
||||
#define CAFFE_SDT_ISARRAY(x) (__builtin_classify_type(x) == 14)
|
||||
#define CAFFE_SDT_ARGSIZE(x) (CAFFE_SDT_ISARRAY(x) ? sizeof(void*) : sizeof(x))
|
||||
#define CAFFE_SDT_IS_ARRAY_POINTER(x) ((__builtin_classify_type(x) == 14) || \
|
||||
(__builtin_classify_type(x) == 5))
|
||||
#define CAFFE_SDT_ARGSIZE(x) (CAFFE_SDT_IS_ARRAY_POINTER(x) \
|
||||
? sizeof(void*) \
|
||||
: sizeof(x))
|
||||
|
||||
// Format of each probe arguments as operand.
|
||||
// Size of the argument tagged with CAFFE_SDT_Sn, with "n" constraint.
|
||||
@ -55,6 +64,8 @@
|
||||
CAFFE_SDT_OPERANDS_6(_1, _2, _3, _4, _5, _6), CAFFE_SDT_ARG(7, _7)
|
||||
#define CAFFE_SDT_OPERANDS_8(_1, _2, _3, _4, _5, _6, _7, _8) \
|
||||
CAFFE_SDT_OPERANDS_7(_1, _2, _3, _4, _5, _6, _7), CAFFE_SDT_ARG(8, _8)
|
||||
#define CAFFE_SDT_OPERANDS_9(_1, _2, _3, _4, _5, _6, _7, _8, _9) \
|
||||
CAFFE_SDT_OPERANDS_8(_1, _2, _3, _4, _5, _6, _7, _8), CAFFE_SDT_ARG(9, _9)
|
||||
|
||||
// Templates to reference the arguments from operands in note section.
|
||||
#define CAFFE_SDT_ARGFMT(no) %n[CAFFE_SDT_S##no]@%[CAFFE_SDT_A##no]
|
||||
@ -67,9 +78,30 @@
|
||||
#define CAFFE_SDT_ARG_TEMPLATE_6 CAFFE_SDT_ARG_TEMPLATE_5 CAFFE_SDT_ARGFMT(6)
|
||||
#define CAFFE_SDT_ARG_TEMPLATE_7 CAFFE_SDT_ARG_TEMPLATE_6 CAFFE_SDT_ARGFMT(7)
|
||||
#define CAFFE_SDT_ARG_TEMPLATE_8 CAFFE_SDT_ARG_TEMPLATE_7 CAFFE_SDT_ARGFMT(8)
|
||||
#define CAFFE_SDT_ARG_TEMPLATE_9 CAFFE_SDT_ARG_TEMPLATE_8 CAFFE_SDT_ARGFMT(9)
|
||||
|
||||
// Semaphore define, declare and probe note format
|
||||
|
||||
#define CAFFE_SDT_SEMAPHORE(provider, name) \
|
||||
caffe_sdt_semaphore_##provider##_##name
|
||||
|
||||
#define CAFFE_SDT_DEFINE_SEMAPHORE(name) \
|
||||
extern "C" { \
|
||||
volatile unsigned short CAFFE_SDT_SEMAPHORE(caffe2, name) \
|
||||
__attribute__((section(CAFFE_SDT_SEMAPHORE_SECTION), used)) = 0; \
|
||||
}
|
||||
|
||||
#define CAFFE_SDT_DECLARE_SEMAPHORE(name) \
|
||||
extern "C" volatile unsigned short CAFFE_SDT_SEMAPHORE(caffe2, name)
|
||||
|
||||
#define CAFFE_SDT_SEMAPHORE_NOTE_0(provider, name) \
|
||||
CAFFE_SDT_ASM_1( CAFFE_SDT_ASM_ADDR 0) /*No Semaphore*/ \
|
||||
|
||||
#define CAFFE_SDT_SEMAPHORE_NOTE_1(provider, name) \
|
||||
CAFFE_SDT_ASM_1(CAFFE_SDT_ASM_ADDR CAFFE_SDT_SEMAPHORE(provider, name))
|
||||
|
||||
// Structure of note section for the probe.
|
||||
#define CAFFE_SDT_NOTE_CONTENT(provider, name, arg_template) \
|
||||
#define CAFFE_SDT_NOTE_CONTENT(provider, name, has_semaphore, arg_template) \
|
||||
CAFFE_SDT_ASM_1(990: CAFFE_SDT_NOP) \
|
||||
CAFFE_SDT_ASM_3( .pushsection .note.stapsdt,"","note") \
|
||||
CAFFE_SDT_ASM_1( .balign 4) \
|
||||
@ -77,8 +109,8 @@
|
||||
CAFFE_SDT_ASM_1(991: .asciz CAFFE_SDT_NOTE_NAME) \
|
||||
CAFFE_SDT_ASM_1(992: .balign 4) \
|
||||
CAFFE_SDT_ASM_1(993: CAFFE_SDT_ASM_ADDR 990b) \
|
||||
CAFFE_SDT_ASM_1( CAFFE_SDT_ASM_ADDR 0) /*Reserved for Semaphore address*/\
|
||||
CAFFE_SDT_ASM_1( CAFFE_SDT_ASM_ADDR 0) /*Reserved for Semaphore name*/ \
|
||||
CAFFE_SDT_ASM_1( CAFFE_SDT_ASM_ADDR 0) /*Reserved for Base Address*/ \
|
||||
CAFFE_SDT_SEMAPHORE_NOTE_##has_semaphore(provider, name) \
|
||||
CAFFE_SDT_ASM_STRING(provider) \
|
||||
CAFFE_SDT_ASM_STRING(name) \
|
||||
CAFFE_SDT_ASM_STRING(arg_template) \
|
||||
@ -86,15 +118,16 @@
|
||||
CAFFE_SDT_ASM_1( .popsection)
|
||||
|
||||
// Main probe Macro.
|
||||
#define CAFFE_SDT_PROBE(provider, name, n, arglist) \
|
||||
#define CAFFE_SDT_PROBE(provider, name, has_semaphore, n, arglist) \
|
||||
__asm__ __volatile__ ( \
|
||||
CAFFE_SDT_NOTE_CONTENT(provider, name, CAFFE_SDT_ARG_TEMPLATE_##n) \
|
||||
CAFFE_SDT_NOTE_CONTENT( \
|
||||
provider, name, has_semaphore, CAFFE_SDT_ARG_TEMPLATE_##n) \
|
||||
:: CAFFE_SDT_OPERANDS_##n arglist \
|
||||
) \
|
||||
|
||||
// Helper Macros to handle variadic arguments.
|
||||
#define CAFFE_SDT_NARG_(_0, _1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
|
||||
#define CAFFE_SDT_NARG_(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
|
||||
#define CAFFE_SDT_NARG(...) \
|
||||
CAFFE_SDT_NARG_(__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||
#define CAFFE_SDT_PROBE_N(provider, name, N, ...) \
|
||||
CAFFE_SDT_PROBE(provider, name, N, (__VA_ARGS__))
|
||||
CAFFE_SDT_NARG_(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||
#define CAFFE_SDT_PROBE_N(provider, name, has_semaphore, N, ...) \
|
||||
CAFFE_SDT_PROBE(provider, name, has_semaphore, N, (__VA_ARGS__))
|
||||
|
Reference in New Issue
Block a user