diff --git a/docs/ddk/tracing.md b/docs/ddk/tracing.md index 3836ac916c362c26e1d03fc8736af884bdc1dec6..1f02b248c302c2864e3641490391c7c45da78261 100644 --- a/docs/ddk/tracing.md +++ b/docs/ddk/tracing.md @@ -87,8 +87,11 @@ 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 driver tracing, -pass `ENABLE_DRIVER_TRACING=false` to make. +`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 +of drivers in Fuchsia tracing, boot the kernel with `driver.tracing.enable=0`. Example: @@ -103,13 +106,13 @@ $ fx build Then boot. With QEMU: ```sh -$ fx run -k -N -c driver.tracing.enable=1 +$ fx run -k -N ``` Or on h/w (augment with options specific to your h/w): ```sh -$ fx serve -- -- driver.tracing.enable=1 +$ fx serve ``` These extra requirements will be removed once tracing support stabilizes. diff --git a/docs/kernel_cmdline.md b/docs/kernel_cmdline.md index ea5fd4c7963efea6b5ae22ba154a63c7fd92c718..beb673c17a97afe13bceacc4f3c7f413eaa47494 100644 --- a/docs/kernel_cmdline.md +++ b/docs/kernel_cmdline.md @@ -88,6 +88,17 @@ ZIRCON\_DRIVER\_BEGIN macro. It is not, for example, the name of the device, which for some drivers is almost identical, except that the device may be named "foo-bar" whereas the driver name must use underscores, e.g., "foo_bar". +## driver.tracing.enable=\<bool> + +Enable or disable support for tracing drivers. +When enabled drivers may participate in [Fuchsia tracing](ddk/tracing.md). + +Implementation-wise, what this option does is tell each devhost whether to +register as "trace provider". + +The default is enabled. This options exists to provide a quick fallback should +a problem arise. + ## gfxconsole.early=\<bool> This option (disabled by default) requests that the kernel start a graphics diff --git a/system/core/devmgr/devhost/devhost.cpp b/system/core/devmgr/devhost/devhost.cpp index 01463b7a86565f715055f13292faa015674447e8..a507c835d07cd03a0ba629e27c9e4b345e8daab6 100644 --- a/system/core/devmgr/devhost/devhost.cpp +++ b/system/core/devmgr/devhost/devhost.cpp @@ -45,6 +45,7 @@ #if ENABLE_DRIVER_TRACING #include "tracing.h" #endif +#include "../shared/env.h" #include "../shared/fidl_txn.h" #include "../shared/log.h" @@ -1182,8 +1183,7 @@ __EXPORT int device_host_main(int argc, char** argv) { #if ENABLE_DRIVER_TRACING { - const char* enable = getenv("driver.tracing.enable"); - if (enable && strcmp(enable, "1") == 0) { + 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); diff --git a/system/core/devmgr/devmgr/coordinator.cpp b/system/core/devmgr/devmgr/coordinator.cpp index b41f7139077964e571afdeabf775ebb0d3b45dab..8b292c4ef74a5716a1d17d6b193c8ad2c6514847 100644 --- a/system/core/devmgr/devmgr/coordinator.cpp +++ b/system/core/devmgr/devmgr/coordinator.cpp @@ -36,6 +36,7 @@ #include <utility> #include "devmgr.h" +#include "../shared/env.h" #include "../shared/fdio.h" #include "../shared/fidl_txn.h" #include "../shared/log.h" diff --git a/system/core/devmgr/devmgr/drivers.cpp b/system/core/devmgr/devmgr/drivers.cpp index 4b3109f9f7c42e9ce5f87909dc120f63344f16ee..556e4d949e368d174aa9dc46629a5a543e66591e 100644 --- a/system/core/devmgr/devmgr/drivers.cpp +++ b/system/core/devmgr/devmgr/drivers.cpp @@ -12,6 +12,7 @@ #include "coordinator.h" #include "devmgr.h" +#include "../shared/env.h" #include "../shared/fdio.h" #include "../shared/log.h" diff --git a/system/core/devmgr/devmgr/main.cpp b/system/core/devmgr/devmgr/main.cpp index ca43ea9b7e025ba9bfe81fe343d2120af026d59f..3ab06d20e3c6a3cec6ed65d80de22d68bbbf460f 100644 --- a/system/core/devmgr/devmgr/main.cpp +++ b/system/core/devmgr/devmgr/main.cpp @@ -40,6 +40,7 @@ #include <lib/zx/time.h> #include <lib/zx/vmo.h> +#include "../shared/env.h" #include "../shared/fdio.h" #include "coordinator.h" #include "devmgr.h" diff --git a/system/core/devmgr/fshost/fshost.h b/system/core/devmgr/fshost/fshost.h index f9b62647219f7584ea213acd7fe1a67c8c93e443..0cd64ae089145d42b8c02d68859970e440e591d6 100644 --- a/system/core/devmgr/fshost/fshost.h +++ b/system/core/devmgr/fshost/fshost.h @@ -16,6 +16,7 @@ #include <zircon/thread_annotations.h> #include <zircon/types.h> +#include "../shared/env.h" #include "../shared/fdio.h" namespace devmgr { diff --git a/system/core/devmgr/rules.mk b/system/core/devmgr/rules.mk index 5909c8a62a98928d6ceb89cbe7a4bd61947d2ef9..ae1b9cac74cba6501fb0a056c98943b419152307 100644 --- a/system/core/devmgr/rules.mk +++ b/system/core/devmgr/rules.mk @@ -19,6 +19,7 @@ MODULE_SRCS += \ $(LOCAL_DIR)/devmgr/devfs.cpp \ $(LOCAL_DIR)/devmgr/drivers.cpp \ $(LOCAL_DIR)/devmgr/fidl.cpp \ + $(LOCAL_DIR)/shared/env.cpp \ $(LOCAL_DIR)/shared/fdio.cpp \ # userboot supports loading via the dynamic linker, so libc (system/ulib/c) @@ -80,6 +81,7 @@ MODULE_SRCS := \ $(LOCAL_DIR)/fshost/block-watcher.cpp \ $(LOCAL_DIR)/fshost/main.cpp \ $(LOCAL_DIR)/fshost/vfs-rpc.cpp \ + $(LOCAL_DIR)/shared/env.cpp \ $(LOCAL_DIR)/shared/fdio.cpp \ MODULE_STATIC_LIBS := \ diff --git a/system/core/devmgr/shared/env.cpp b/system/core/devmgr/shared/env.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7f716f1121d477c4b53e09528660f5bc171fd0a --- /dev/null +++ b/system/core/devmgr/shared/env.cpp @@ -0,0 +1,25 @@ +// 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. + +#include "env.h" + +#include <stdlib.h> +#include <string.h> + +namespace devmgr { + +bool getenv_bool(const char* key, bool default_value) { + const char* value = getenv(key); + if (value == nullptr) { + return default_value; + } + if ((strcmp(value, "0") == 0) || + (strcmp(value, "false") == 0) || + (strcmp(value, "off") == 0)) { + return false; + } + return true; +} + +} // namespace devmgr diff --git a/system/core/devmgr/shared/env.h b/system/core/devmgr/shared/env.h new file mode 100644 index 0000000000000000000000000000000000000000..88f7b38567f14d1239bcf22cbe65def28bce702f --- /dev/null +++ b/system/core/devmgr/shared/env.h @@ -0,0 +1,14 @@ +// 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. + +#pragma once + +namespace devmgr { + +// getenv_bool looks in the environment for |key|. If not found, it +// returns |default_value|. If found, it returns false if the found +// value matches "0", "off", or "false", otherwise it returns true. +bool getenv_bool(const char* key, bool default_value); + +} // namespace devmgr diff --git a/system/core/devmgr/shared/fdio.cpp b/system/core/devmgr/shared/fdio.cpp index 94d1494011964b41a5d45e126f101670bc06e8f9..03cf73e54c01f7044215655686ac6eecebaa470a 100644 --- a/system/core/devmgr/shared/fdio.cpp +++ b/system/core/devmgr/shared/fdio.cpp @@ -174,17 +174,4 @@ zx_status_t devmgr_launch_cmdline( return status; } -bool getenv_bool(const char* key, bool default_value) { - const char* value = getenv(key); - if (value == nullptr) { - return default_value; - } - if ((strcmp(value, "0") == 0) || - (strcmp(value, "false") == 0) || - (strcmp(value, "off") == 0)) { - return false; - } - return true; -} - } // namespace diff --git a/system/core/devmgr/shared/fdio.h b/system/core/devmgr/shared/fdio.h index a6e062b904046786e041b3b8c231b643aab530dc..3d785ee956232e9fc7a477a666e7644b5c0fd6b2 100644 --- a/system/core/devmgr/shared/fdio.h +++ b/system/core/devmgr/shared/fdio.h @@ -51,11 +51,6 @@ zx_status_t devmgr_launch_cmdline( const zx_handle_t* handles, const uint32_t* types, size_t hcount, zx::process* proc_out, uint32_t flags); -// getenv_bool looks in the environment for |key|. If not found, it -// returns |default_value|. If found, it returns false if the found -// value matches "0", "off", or "false", otherwise it returns true. -bool getenv_bool(const char* key, bool default_value); - // The variable to set on the kernel command line to enable ld.so tracing // of the processes we launch. #define LDSO_TRACE_CMDLINE "ldso.trace" diff --git a/system/ulib/driver/rules.mk b/system/ulib/driver/rules.mk index 4e3355e53ccf1c436f123f2cc6a763246c8e9a20..f9e82d9043c181b2d84bd33bea51a42ae121d277 100644 --- a/system/ulib/driver/rules.mk +++ b/system/ulib/driver/rules.mk @@ -4,7 +4,8 @@ LOCAL_DIR := $(GET_LOCAL_DIR) -DEVHOST_SRCS := system/core/devmgr/devhost +LOCAL_DEVMGR_ROOT := system/core/devmgr +LOCAL_DEVHOST_SRCS := $(LOCAL_DEVMGR_ROOT)/devhost MODULE := $(LOCAL_DIR) @@ -18,15 +19,16 @@ MODULE_SO_NAME := driver MODULE_COMPILEFLAGS := -fvisibility=hidden MODULE_SRCS := \ - $(DEVHOST_SRCS)/devhost.cpp \ - $(DEVHOST_SRCS)/api.cpp \ - $(DEVHOST_SRCS)/core.cpp \ - $(DEVHOST_SRCS)/rpc-server.cpp \ - $(DEVHOST_SRCS)/zx-device.cpp \ + $(LOCAL_DEVHOST_SRCS)/devhost.cpp \ + $(LOCAL_DEVHOST_SRCS)/api.cpp \ + $(LOCAL_DEVHOST_SRCS)/core.cpp \ + $(LOCAL_DEVHOST_SRCS)/rpc-server.cpp \ + $(LOCAL_DEVHOST_SRCS)/zx-device.cpp \ + $(LOCAL_DEVMGR_ROOT)/shared/env.cpp \ ifeq ($(call TOBOOL,$(ENABLE_DRIVER_TRACING)),true) MODULE_SRCS += \ - $(DEVHOST_SRCS)/tracing.cpp + $(LOCAL_DEVHOST_SRCS)/tracing.cpp MODULE_HEADER_DEPS := \ system/ulib/trace-provider endif