Skip to content

Commit

Permalink
[vioscsi] clean up and simplify WPP tracing https://issues.redhat.com…
Browse files Browse the repository at this point in the history
…/browse/RHEL-24805

Signed-off-by: Vadim Rozenfeld <[email protected]>
  • Loading branch information
vrozenfe committed Mar 26, 2024
1 parent 908c212 commit 7a16469
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
82 changes: 53 additions & 29 deletions vioscsi/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
#ifndef ___TRACING_H___
#define ___TRACING_H___

//#define DBG 1
//#define PRINT_DEBUG 1
//#define COM_DEBUG 1

#define EVENT_TRACING 1

#include <ntddk.h>
#include <storport.h>
Expand All @@ -42,10 +41,15 @@
#define UCHAR_MAX 0xFF
#define DbgGetScsiOp(Srb) (SRB_CDB(Srb) ? SRB_CDB(Srb)->CDB6GENERIC.OperationCode : UCHAR_MAX)

char *DbgGetScsiOpStr(UCHAR opCode);
char *DbgGetScsiOpStr(IN UCHAR opCode);
void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath);

#if !defined(DBG)
#define EVENT_TRACING 1
#if !defined(EVENT_TRACING)
#define define DBG 1
#define PRINT_DEBUG 1
#if !defined(PRINT_DEBUG)
#define COM_DEBUG 1
#endif
#endif

#if !defined(EVENT_TRACING)
Expand Down Expand Up @@ -79,8 +83,6 @@ extern int nVioscsiDebugLevel;
#define VioScsiDbgBreak()
#endif

void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath);

#define ENTER_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n",__FUNCTION__)
#define EXIT_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n",__FUNCTION__)
#define EXIT_ERR() RhelDbgPrint(TRACE_LEVEL_ERROR, " <--> %s (%d).\n", __FUNCTION__, __LINE__)
Expand All @@ -105,37 +107,59 @@ void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING R
WPP_DEFINE_BIT(TRACE_LEVEL_VERBOSE) /* bit 5 = 0x00000020 */ \
)

#define WPP_Flags_LEVEL_LOGGER(Flags, level) \
WPP_LEVEL_LOGGER(Flags)
#define WPP_Flags_LEVEL_ENABLED(Flags, level) \
(level <= virtioDebugLevel)

#define WPP_FLAGS_LEVEL_STATUS_LOGGER(Flags, level, status) \
WPP_LEVEL_LOGGER(Flags)
#define WPP_Flags_LEVEL_STATUS_ENABLED(Flags, level, status) \
(level <= virtioDebugLevel)

// begin_wpp config
// USEPREFIX (RhelDbgPrint, "%!STDPREFIX! %!FUNC!");
// FUNC RhelDbgPrint(LEVEL, MSG, ...);
// USEPREFIX (ENTER_FN, "%!STDPREFIX! ---> %!FUNC!");
// FUNC ENTER_FN{LEVEL=TRACE_LEVEL_VERBOSE}(...);
// USEPREFIX (EXIT_FN, "%!STDPREFIX! <--- %!FUNC!");
// FUNC EXIT_FN{LEVEL=TRACE_LEVEL_VERBOSE}(...);
// end_wpp

#define WPP_Flags_LEVEL_LOGGER(Flags, level) WPP_LEVEL_LOGGER(Flags)
#define WPP_Flags_LEVEL_ENABLED(Flags, level) \
(WPP_LEVEL_ENABLED(Flags) && \
WPP_CONTROL(WPP_BIT_ ## Flags).Level >= level)

// begin_wpp config
// USEPREFIX (ENTER_FN, "%!STDPREFIX! [%!FUNC!] --> entry");
// FUNC ENTER_FN{ENTRYLEVEL=TRACE_LEVEL_VERBOSE}(...);
// end_wpp

#define WPP_ENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL)
#define WPP_ENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL)

// begin_wpp config
// USEPREFIX (EXIT_FN, "%!STDPREFIX! [%!FUNC!] <-- exit");
// FUNC EXIT_FN{EXITLEVEL=TRACE_LEVEL_VERBOSE}(...);
// end_wpp
#define WPP_EXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL)
#define WPP_EXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL)

// begin_wpp config
// USEPREFIX (EXIT_ERR, "%!STDPREFIX! <--> %!FUNC! ERROR line %d", __LINE__);
// FUNC EXIT_ERR{LEVEL=TRACE_LEVEL_ERROR}(...);
// FUNC EXIT_ERR{ERRORLEVEL=TRACE_LEVEL_ERROR}(...);
// end_wpp
#define WPP_ERRORLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL)
#define WPP_ERRORLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL)

// begin_wpp config
// USEPREFIX (ENTER_FN_SRB(PVOID Srb), "%!STDPREFIX! ---> %!FUNC! 0x%p.", Srb);
// FUNC ENTER_FN_SRB{LEVEL=TRACE_LEVEL_VERBOSE}(...);
// FUNC ENTER_FN_SRB{SRBENTRYLEVEL=TRACE_LEVEL_INFORMATION}(...);
// end_wpp
#define WPP_SRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL)
#define WPP_SRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL)

// begin_wpp config
// USEPREFIX (EXIT_FN_SRB(PVOID Srb), "%!STDPREFIX! <--- %!FUNC! 0x%p.", Srb);
// FUNC EXIT_FN_SRB{LEVEL=TRACE_LEVEL_VERBOSE}(...);
// FUNC EXIT_FN_SRB{SRBEXITLEVEL=TRACE_LEVEL_INFORMATION}(...);
// end_wpp
#define WPP_SRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL)
#define WPP_SRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL)

// begin_wpp config
// USEPREFIX (LOG_SRB_INFO(PVOID Srb), "%!STDPREFIX! %!FUNC! <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb);
// FUNC LOG_SRB_INFO{LEVEL=TRACE_LEVEL_INFORMATION}(...);

// FUNC LOG_SRB_INFO{SRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...);
// end_wpp

#define WPP_CHECK_FOR_NULL_STRING
#define WPP_SRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL)
#define WPP_SRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL)

#endif

#endif //__TRACING_H___
11 changes: 8 additions & 3 deletions vioscsi/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING R

tDebugPrintFunc VirtioDebugPrintProc;
#else
bDebugPrint = 1;
virtioDebugLevel = 0xFF;
nViostorDebugLevel = 0xFF;
void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
//TBD - Read nDebugLevel and bDebugPrint from the registry
bDebugPrint = 0;
virtioDebugLevel = 0;
nVioscsiDebugLevel = 4;// TRACE_LEVEL_ERROR;
}

tDebugPrintFunc VirtioDebugPrintProc = DbgPrint;
#endif

Expand Down
11 changes: 4 additions & 7 deletions vioscsi/vioscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,10 @@ DriverEntry(

#ifdef EVENT_TRACING
STORAGE_TRACE_INIT_INFO initInfo;
#else
#ifdef DBG
InitializeDebugPrints((PDRIVER_OBJECT)DriverObject, (PUNICODE_STRING)RegistryPath);
#endif
#endif

InitializeDebugPrints((PDRIVER_OBJECT)DriverObject, (PUNICODE_STRING)RegistryPath);

IsCrashDumpMode = FALSE;
RhelDbgPrint(TRACE_LEVEL_FATAL, " Vioscsi driver started...built on %s %s\n", __DATE__, __TIME__);
if (RegistryPath == NULL) {
Expand Down Expand Up @@ -695,10 +693,9 @@ VioScsiPoolAlloc(
adaptExt->poolOffset += (ULONG)size;
RtlZeroMemory(ptr, size);
return ptr;
} else {
RhelDbgPrint(TRACE_LEVEL_FATAL, " Out of memory %Id \n", size);
return NULL;
}
RhelDbgPrint(TRACE_LEVEL_FATAL, " Out of memory %Id \n", size);
return NULL;
}

BOOLEAN
Expand Down

0 comments on commit 7a16469

Please sign in to comment.