From a6e3ae346de80c325264d4f753122ab1dff3ccca Mon Sep 17 00:00:00 2001
From: Doug Evans <dje@google.com>
Date: Fri, 8 Feb 2019 17:07:17 -0800
Subject: [PATCH] [driver tracing] Remove ENABLE_DRIVER_TRACING conditional
 compilation

Driver tracing support is now always compiled in.

ZX-3317 #done

Tested: CQ
Change-Id: Ic5e9f952f3f93a9000404bb33bae62456ad4d6ae
---
 zircon/docs/ddk/tracing.md                    | 20 +++----------------
 zircon/make/engine.mk                         |  7 -------
 zircon/system/core/devmgr/devhost/devhost.cpp | 17 ++++++----------
 zircon/system/dev/block/sdmmc/rules.mk        |  3 +--
 zircon/system/dev/display/display/rules.mk    |  3 +--
 zircon/system/dev/input/hid/rules.mk          |  3 +--
 zircon/system/dev/input/i2c-hid/rules.mk      |  3 +--
 .../system/ulib/ddk/include/ddk/trace/event.h |  7 -------
 zircon/system/ulib/driver/rules.mk            | 12 -----------
 .../ulib/trace-engine/ddk-disabled-exports.ld | 18 -----------------
 zircon/system/ulib/trace-engine/rules.mk      | 15 ++++----------
 11 files changed, 17 insertions(+), 91 deletions(-)
 delete mode 100644 zircon/system/ulib/trace-engine/ddk-disabled-exports.ld

diff --git a/zircon/docs/ddk/tracing.md b/zircon/docs/ddk/tracing.md
index a4808b3ecc3..c3ae45d91c8 100644
--- a/zircon/docs/ddk/tracing.md
+++ b/zircon/docs/ddk/tracing.md
@@ -62,35 +62,21 @@ unrelated data from a different trace provider.
 The event name is included in the trace to describe what the event
 is about. It is typically unique for each event.
 
-Note that currently the default is that no code will be generated
-by the addition of these `TRACE_*()` macros. Akin to <assert.h>'s use of
-`#define NDEBUG` to disable `assert()`s, tracing uses `#define NTRACE` to
-disable tracing. `NTRACE` is currently defined by default unless
-`ENABLE_DRIVER_TRACING=true` is passed to `make`. See below.
-
 ### Makefile additions
 
 The following addition to your driver's `rules.mk` file is needed to
 pick up tracing support:
 
 ```make
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
 MODULE_STATIC_LIBS += system/ulib/trace.driver
-endif
 MODULE_HEADER_DEPS += system/ulib/trace system/ulib/trace-engine
 ```
 
 ## Booting with tracing
 
-To be super conservative, not only does tracing currently require a special
-compile flag to enable it: `ENABLE_DRIVER_TRACING=true`,
-it also requires an extra kernel command line flag to enable it:
-`driver.tracing.enable=1`
-
-`ENABLE_DRIVER_TRACING=true` is now the default. To disable compiling in
-driver tracing support, pass `ENABLE_DRIVER_TRACING=false` to make.
-
-`driver.tracing.enable=1` is also now the default. To disable partipation
+To be conservative, tracing uses a kernel command line flag to enable it:
+`driver.tracing.enable=1`.
+`driver.tracing.enable=1` is the default. To disable partipation
 of drivers in Fuchsia tracing, boot the kernel with `driver.tracing.enable=0`.
 
 Example:
diff --git a/zircon/make/engine.mk b/zircon/make/engine.mk
index cdcc727d097..7cfb40582f3 100644
--- a/zircon/make/engine.mk
+++ b/zircon/make/engine.mk
@@ -29,8 +29,6 @@ ENABLE_LOCK_DEP ?= false
 ENABLE_LOCK_DEP_TESTS ?= $(ENABLE_LOCK_DEP)
 DISABLE_UTEST ?= false
 ENABLE_ULIB_ONLY ?= false
-ENABLE_DRIVER_TRACING ?= true
-ENABLE_DRIVER_TRACING := $(call TOBOOL,$(ENABLE_DRIVER_TRACING))
 USE_ASAN ?= false
 USE_SANCOV ?= false
 USE_PROFILE ?= false
@@ -218,11 +216,6 @@ USER_CFLAGS :=
 USER_CPPFLAGS :=
 USER_ASMFLAGS :=
 
-# Allow driver tracing to be completely disabled (as if it didn't exist).
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
-USER_COMPILEFLAGS += -DENABLE_DRIVER_TRACING=1
-endif
-
 # Additional flags for dynamic linking, both for dynamically-linked
 # executables and for shared libraries.
 USER_LDFLAGS := \
diff --git a/zircon/system/core/devmgr/devhost/devhost.cpp b/zircon/system/core/devmgr/devhost/devhost.cpp
index 0bc58560ece..fe94cb76356 100644
--- a/zircon/system/core/devmgr/devhost/devhost.cpp
+++ b/zircon/system/core/devmgr/devhost/devhost.cpp
@@ -42,9 +42,7 @@
 
 #include "../shared/async-loop-owned-rpc-handler.h"
 #include "main.h"
-#if ENABLE_DRIVER_TRACING
 #include "tracing.h"
-#endif
 #include "../shared/env.h"
 #include "../shared/fidl_txn.h"
 #include "../shared/log.h"
@@ -1209,17 +1207,14 @@ __EXPORT int device_host_main(int argc, char** argv) {
 
     zx_status_t r;
 
-#if ENABLE_DRIVER_TRACING
-    {
-        if (getenv_bool("driver.tracing.enable", true)) {
-            r = devhost_start_trace_provider();
-            if (r != ZX_OK) {
-                log(INFO, "devhost: error registering as trace provider: %d\n", r);
-                // This is not a fatal error.
-            }
+    if (getenv_bool("driver.tracing.enable", true)) {
+        r = devhost_start_trace_provider();
+        if (r != ZX_OK) {
+            log(INFO, "devhost: error registering as trace provider: %d\n", r);
+            // This is not a fatal error.
         }
     }
-#endif
+
     if ((r = SetupRootDevcoordinatorConnection(std::move(root_conn_channel))) != ZX_OK) {
         log(ERROR, "devhost: could not watch rpc channel: %d\n", r);
         return -1;
diff --git a/zircon/system/dev/block/sdmmc/rules.mk b/zircon/system/dev/block/sdmmc/rules.mk
index eac40c68f9c..cd9ea3442e5 100644
--- a/zircon/system/dev/block/sdmmc/rules.mk
+++ b/zircon/system/dev/block/sdmmc/rules.mk
@@ -32,9 +32,8 @@ MODULE_BANJO_LIBS := \
     system/banjo/ddk-protocol-sdio \
     system/banjo/ddk-protocol-sdmmc \
 
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
+# Driver tracing additions.
 MODULE_STATIC_LIBS += system/ulib/trace.driver
-endif
 MODULE_HEADER_DEPS += system/ulib/trace system/ulib/trace-engine
 
 include make/module.mk
diff --git a/zircon/system/dev/display/display/rules.mk b/zircon/system/dev/display/display/rules.mk
index 8b327f3dc56..e5aace4f283 100644
--- a/zircon/system/dev/display/display/rules.mk
+++ b/zircon/system/dev/display/display/rules.mk
@@ -44,9 +44,8 @@ MODULE_BANJO_LIBS := \
     system/banjo/ddk-protocol-display-controller \
     system/banjo/ddk-protocol-i2cimpl \
 
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
+# Driver tracing additions.
 MODULE_STATIC_LIBS += system/ulib/trace.driver
-endif
 MODULE_HEADER_DEPS += system/ulib/trace system/ulib/trace-engine
 
 include make/module.mk
diff --git a/zircon/system/dev/input/hid/rules.mk b/zircon/system/dev/input/hid/rules.mk
index cd7423eb04a..510c0a8b3a0 100644
--- a/zircon/system/dev/input/hid/rules.mk
+++ b/zircon/system/dev/input/hid/rules.mk
@@ -30,9 +30,8 @@ MODULE_LIBS := \
 MODULE_BANJO_LIBS := \
     system/banjo/ddk-protocol-hidbus \
 
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
+# Driver tracing additions.
 MODULE_STATIC_LIBS += system/ulib/trace.driver
-endif
 MODULE_HEADER_DEPS += system/ulib/trace system/ulib/trace-engine
 
 include make/module.mk
diff --git a/zircon/system/dev/input/i2c-hid/rules.mk b/zircon/system/dev/input/i2c-hid/rules.mk
index 78e26173a05..f49a1d37487 100644
--- a/zircon/system/dev/input/i2c-hid/rules.mk
+++ b/zircon/system/dev/input/i2c-hid/rules.mk
@@ -18,9 +18,8 @@ MODULE_BANJO_LIBS := \
     system/banjo/ddk-protocol-hidbus \
     system/banjo/ddk-protocol-i2c \
 
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
+# Driver tracing additions.
 MODULE_STATIC_LIBS += system/ulib/trace.driver
-endif
 MODULE_HEADER_DEPS += system/ulib/trace system/ulib/trace-engine
 
 include make/module.mk
diff --git a/zircon/system/ulib/ddk/include/ddk/trace/event.h b/zircon/system/ulib/ddk/include/ddk/trace/event.h
index af557cf3235..6d4bc15e902 100644
--- a/zircon/system/ulib/ddk/include/ddk/trace/event.h
+++ b/zircon/system/ulib/ddk/include/ddk/trace/event.h
@@ -23,13 +23,6 @@
 #ifndef DDK_TRACE_EVENT_H_
 #define DDK_TRACE_EVENT_H_
 
-// While driver tracing support is under development,
-// one must pass ENABLE_DRIVER_TRACING=true to make.
-#if !ENABLE_DRIVER_TRACING
-#undef NTRACE
-#define NTRACE
-#endif
-
 // For now userspace and DDK tracing share the same API and implementation.
 #include <trace/internal/event_common.h>
 
diff --git a/zircon/system/ulib/driver/rules.mk b/zircon/system/ulib/driver/rules.mk
index 4a05fdc31fa..76184f6710f 100644
--- a/zircon/system/ulib/driver/rules.mk
+++ b/zircon/system/ulib/driver/rules.mk
@@ -26,12 +26,10 @@ MODULE_SRCS := \
 	$(LOCAL_DEVHOST_SRCS)/zx-device.cpp \
 	$(LOCAL_DEVMGR_ROOT)/shared/env.cpp \
 
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
 MODULE_SRCS += \
     $(LOCAL_DEVHOST_SRCS)/tracing.cpp
 MODULE_HEADER_DEPS := \
     system/ulib/trace-provider
-endif
 
 MODULE_FIDL_LIBS := \
     system/fidl/fuchsia-device \
@@ -61,8 +59,6 @@ MODULE_STATIC_LIBS := \
 MODULE_STATIC_LIBS += \
     system/ulib/trace-engine.driver
 
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
-
 MODULE_FIDL_LIBS += \
     system/fidl/fuchsia-tracelink \
 
@@ -74,14 +70,6 @@ MODULE_STATIC_LIBS += \
 # references to ensure everything is present.
 MODULE_EXTRA_OBJS := system/ulib/trace-engine/ddk-exports.ld
 
-else
-
-# Some symbols still need to be present even if tracing is disabled.
-# See the linker script for details.
-MODULE_EXTRA_OBJS := system/ulib/trace-engine/ddk-disabled-exports.ld
-
-endif
-
 MODULE_LIBS := system/ulib/fdio system/ulib/zircon system/ulib/c
 
 include make/module.mk
diff --git a/zircon/system/ulib/trace-engine/ddk-disabled-exports.ld b/zircon/system/ulib/trace-engine/ddk-disabled-exports.ld
deleted file mode 100644
index 8e5b6b6297d..00000000000
--- a/zircon/system/ulib/trace-engine/ddk-disabled-exports.ld
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright 2018 The Fuchsia Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/*
- * This is an input linker script used in linking libdriver.so.
- * The linker is pulling in our symbols from an archive, thus they won't get
- * pulled in unless they are referenced. 
- * This file injects synthetic references to keep the symbols alive.
- *
- * N.B. This file is used when tracing is disabled in the DDK because these
- * symbols can be used by tracing clients even when tracing is disabled with
- * #define NTRACE.
- */
-
-EXTERN(trace_generate_nonce)
diff --git a/zircon/system/ulib/trace-engine/rules.mk b/zircon/system/ulib/trace-engine/rules.mk
index 455461ad6b9..418f45982f6 100644
--- a/zircon/system/ulib/trace-engine/rules.mk
+++ b/zircon/system/ulib/trace-engine/rules.mk
@@ -82,25 +82,18 @@ MODULE_TYPE := userlib
 MODULE_COMPILEFLAGS += -fvisibility=hidden
 MODULE_COMPILEFLAGS += -DDDK_TRACING
 
-# trace_generate_nonce() exists even when driver tracing is disabled
 MODULE_SRCS := \
-    $(LOCAL_DIR)/nonce.cpp
-
-MODULE_STATIC_LIBS := \
-    system/ulib/fbl
-
-ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true)
-MODULE_SRCS += \
     $(LOCAL_DIR)/context.cpp \
     $(LOCAL_DIR)/context_api.cpp \
-    $(LOCAL_DIR)/engine.cpp
+    $(LOCAL_DIR)/engine.cpp \
+    $(LOCAL_DIR)/nonce.cpp
 
-MODULE_STATIC_LIBS += \
+MODULE_STATIC_LIBS := \
     system/ulib/async.cpp \
     system/ulib/async \
+    system/ulib/fbl \
     system/ulib/zx \
     system/ulib/zxcpp
-endif
 
 MODULE_LIBS := $(LOCAL_LIBS)
 
-- 
GitLab