From patchwork Mon Jun 26 18:42:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129004 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C9D9242D5F; Mon, 26 Jun 2023 20:42:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 717EE4282D; Mon, 26 Jun 2023 20:42:54 +0200 (CEST) Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by mails.dpdk.org (Postfix) with ESMTP id 7A7A84013F for ; Mon, 26 Jun 2023 20:42:52 +0200 (CEST) Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-263036d54b9so579899a91.0 for ; Mon, 26 Jun 2023 11:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687804971; x=1690396971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c9U9tE8eQy1k4qcUEU4AcbFdTUvpWcsxv69ky9xBapE=; b=uW0hwNlxf2vdvgQfKwJtJdaxv9XAIYGAObq9sw1Vvqlh4Viwjsdb54ajMFJGoFWaMH bv2dZe1arCZMhGBnVpeb+y+HCs/TffoxTXMwjA/l158/dLCPrQdF93ZGKj8gH+WSe67i G2ZFAPQi/LfKudzwPS2Pp9V+Fiyk12xIjcfnhbpVQf6INS4Xr9H1ilHIJoMgLBoo28Ta iOOt/676TWDDoBYlzNV77GFxy50TpGsbv3LiTigJyrC/fpEbA60uZN2MMKl2WzAgBg8Y uqWy0Q+MFqMx3TNnDrouODvfmIbRCDqScHhXOO2AgyJ12LvCH5X94Wo/qM2d8LcdoRof HSSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804971; x=1690396971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c9U9tE8eQy1k4qcUEU4AcbFdTUvpWcsxv69ky9xBapE=; b=jewwou4TDxRmvB2fP4Q4ln9yWD+ebSThRfaVPYMeCOcnY/9bjxLZVbstPXRLxCOs9q NYkMnPm+/TQdLgXbCzWDeoFzTadJjiWrofFIWYPNytaLgqt7UoRy/Ohl3DntTn1m/llC twxhl+95CB1LwBm4W5g6v6GYsWdZKDTagMub9x2y7Y3V3X1YVKwdG7JPhdmnVeXOvanz v+jbuR3AnbLTkqE5YPsw2r3sBt0VqONwOBxPA0fQHGHXZwMqATpSPUezvFNScJWvJAos CYPt0B0YMG4nmC8B6dMk/Y8VhRynVyTGnL2hecY5HuJ9KsS0odqEF4+1LQkFbCEs8kWq Da/w== X-Gm-Message-State: AC+VfDwZ1gJGD+XyQJfxwhVfGz1keBbAz50z8d1PURqez2XG8UWD98+B RYPV2xXgu/6rD/4xmITmY7m+EpoxaQEIsfKp0x/YFg== X-Google-Smtp-Source: ACHHUZ6lpWXw6fZ+MN5uKbxk/snPMQk7C0yTYuPOjrIru6V1y4Q8CJnyzgF87DHC2zua1EsoTmXvUA== X-Received: by 2002:a17:90b:e8d:b0:262:e598:6046 with SMTP id fv13-20020a17090b0e8d00b00262e5986046mr5662110pjb.28.1687804971389; Mon, 26 Jun 2023 11:42:51 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h17-20020a17090adb9100b0024e37e0a67dsm4846577pjv.20.2023.06.26.11.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:42:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v4 1/5] eal: unify logging code for FreeBsd and Linux Date: Mon, 26 Jun 2023 11:42:12 -0700 Message-Id: <20230626184223.155390-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626184223.155390-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230626184223.155390-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org FreeBSD logging code was not using syslog and did not have the same options as Linux. Move the log writing code to common source tree. Signed-off-by: Stephen Hemminger --- .../freebsd_gsg/freebsd_eal_parameters.rst | 27 +++++++++++++++++++ lib/eal/freebsd/eal.c | 7 +++++ lib/eal/linux/meson.build | 1 - lib/eal/{linux => unix}/eal_log.c | 0 lib/eal/unix/meson.build | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) rename lib/eal/{linux => unix}/eal_log.c (100%) diff --git a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst index fba467a2ce92..9270d9fa3bfc 100644 --- a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst +++ b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst @@ -18,3 +18,30 @@ FreeBSD-specific EAL parameters ------------------------------- There are currently no FreeBSD-specific EAL command-line parameters available. + +Other options +~~~~~~~~~~~~~ + +* ``--syslog `` + + Set syslog facility. Valid syslog facilities are:: + + auth + cron + daemon + ftp + kern + lpr + mail + news + syslog + user + uucp + local0 + local1 + local2 + local3 + local4 + local5 + local6 + local7 diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 7008303e112a..6df6873e3889 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -52,6 +52,7 @@ #include "eal_hugepages.h" #include "eal_options.h" #include "eal_memcfg.h" +#include "eal_log.h" #include "eal_trace.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -759,6 +760,12 @@ rte_eal_init(int argc, char **argv) #endif } + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + return -1; + } + /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/eal/linux/meson.build b/lib/eal/linux/meson.build index 5af456db9edb..e99ebed25692 100644 --- a/lib/eal/linux/meson.build +++ b/lib/eal/linux/meson.build @@ -11,7 +11,6 @@ sources += files( 'eal_hugepage_info.c', 'eal_interrupts.c', 'eal_lcore.c', - 'eal_log.c', 'eal_memalloc.c', 'eal_memory.c', 'eal_thread.c', diff --git a/lib/eal/linux/eal_log.c b/lib/eal/unix/eal_log.c similarity index 100% rename from lib/eal/linux/eal_log.c rename to lib/eal/unix/eal_log.c diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build index cc7d67dd321d..37d07594df29 100644 --- a/lib/eal/unix/meson.build +++ b/lib/eal/unix/meson.build @@ -6,6 +6,7 @@ sources += files( 'eal_file.c', 'eal_filesystem.c', 'eal_firmware.c', + 'eal_log.c', 'eal_unix_memory.c', 'eal_unix_thread.c', 'eal_unix_timer.c', From patchwork Mon Jun 26 18:42:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129005 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0F9B942D5F; Mon, 26 Jun 2023 20:43:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 82E5542BDA; Mon, 26 Jun 2023 20:42:55 +0200 (CEST) Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by mails.dpdk.org (Postfix) with ESMTP id 94EE841148 for ; Mon, 26 Jun 2023 20:42:53 +0200 (CEST) Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-39eab4bbe8aso2590099b6e.1 for ; Mon, 26 Jun 2023 11:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687804972; x=1690396972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BXFQnhgwaB8ReFX0BeRWCGxQKFeLEqIvzBfOxM7c12w=; b=OeV+BfJ2J6Ub/9ldy/L3GIMtuANeTsxX7Tz2lDObTvrvuqBJSpQRIvklry8bT3DDMm DXpcS9Um4v+Taot2/InEBE0KIuaPi6a0ARGEzP5Klc1rmDkvpaVX1oxfvU70p7ZbWC6/ 2No99xP37zQqHpAUBnz80iCo3UZK9Xd71t7E94iXUq+Np43bkMcPGM0q5xIe5FJ22FZ6 /6BQwDd/3uY2oexDy1Rz9Q9QX8bTVw33KkSb5kGAGGQgl/yP3ew6CwGxYZrdLk374sCc nfPeOq0zBaaycGL8RmIndLo5uzXD7R8FupfGK53OEeqtafD0RWN8L+E/eL7laTtICO8+ Jm7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804972; x=1690396972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BXFQnhgwaB8ReFX0BeRWCGxQKFeLEqIvzBfOxM7c12w=; b=F7QZm+7N95GqeVi0GPJIt1pHL3qiroASKKw7blyXXscAAv3BInvoxF5AeemoqiRV0x WMUXtmJW3o+JHfSebAyS8N86kKfMo5ZDembqDYzG53v9jX4C4ODTUf1buFoRHhqGYpoF 0n5KHcu0YYPV9VjPq7EI7jH/9aiMmYGutkuMjyQcowJIKb01mEVCxNxPHZmBVM6N06XN CcSxM9Au7DS/ySg3Xot5RfDbiGwFcNKBkQKldn6wDP0NaATghmtL02S1AGwOMUv5x58/ RPA1i7iT8LC3M2oA1XWYo30H8BF50DxsEO0wcFchnBrFlk9Y10kU7fje+QcdhGxZpDUS LAiQ== X-Gm-Message-State: AC+VfDwtc1UEWA0BDzGHSjnCrfZtCiQjCTf+G9Ag22UpucEaMDYTCPxr F1z9vw8fO3sQLsO1WVlhb0bosBz5jHH8EgOo9E9psg== X-Google-Smtp-Source: ACHHUZ7R1MFyirV/G/ovPyL/KcKR2XKbFVoN1B2+O0L9MBurR1TNJFDcB2a4IWpRIMdkd2Ie9LgCEA== X-Received: by 2002:a05:6808:1392:b0:3a1:b2d4:5f64 with SMTP id c18-20020a056808139200b003a1b2d45f64mr12868303oiw.54.1687804972496; Mon, 26 Jun 2023 11:42:52 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h17-20020a17090adb9100b0024e37e0a67dsm4846577pjv.20.2023.06.26.11.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:42:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Keith Wiles , Bruce Richardson , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Subject: [PATCH v4 2/5] eal: turn off getopt_long error message during eal_log_level Date: Mon, 26 Jun 2023 11:42:13 -0700 Message-Id: <20230626184223.155390-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626184223.155390-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230626184223.155390-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If DPDK application is given a bogus option, the error message would get printed twice. Once during scan for log level and again during parsing of arguments. Example: # ./build/app/dpdk-testpmd --bogus ./build/app/dpdk-testpmd: unrecognized option '--bogus' EAL: Detected CPU lcores: 16 EAL: Detected NUMA nodes: 1 ./build/app/dpdk-testpmd: unrecognized option '--bogus' Usage: ./build/app/dpdk-testpmd [options] Fix by suppressing printing error message on first pass. Signed-off-by: Keith Wiles Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 2 ++ lib/eal/linux/eal.c | 2 ++ lib/eal/windows/eal.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6df6873e3889..70087837da18 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -381,6 +381,7 @@ eal_log_level_parse(int argc, char **argv) argvopt = argv; optind = 1; optreset = 1; + opterr = 0; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { @@ -424,6 +425,7 @@ eal_parse_args(int argc, char **argv) argvopt = argv; optind = 1; optreset = 1; + opterr = 1; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 145afafde234..60bb130aea15 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -561,6 +561,7 @@ eal_log_level_parse(int argc, char **argv) argvopt = argv; optind = 1; + opterr = 0; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { @@ -638,6 +639,7 @@ eal_parse_args(int argc, char **argv) argvopt = argv; optind = 1; + opterr = 1; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 2d7a0e9ab27e..0800a9e5c2d2 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -106,6 +106,8 @@ eal_log_level_parse(int argc, char **argv) struct internal_config *internal_conf = eal_get_internal_configuration(); + opterr = 0; + argvopt = argv; eal_reset_internal_config(internal_conf); @@ -143,6 +145,7 @@ eal_parse_args(int argc, char **argv) eal_get_internal_configuration(); argvopt = argv; + opterr = 1; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { From patchwork Mon Jun 26 18:42:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129006 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E85F742D5F; Mon, 26 Jun 2023 20:43:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AAEE842D10; Mon, 26 Jun 2023 20:42:57 +0200 (CEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id 83C2542B8C for ; Mon, 26 Jun 2023 20:42:54 +0200 (CEST) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-66f3fc56ef4so1256370b3a.0 for ; Mon, 26 Jun 2023 11:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687804973; x=1690396973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vVW03ARTqWY9Do/0GxaVPJKlzSZSxWklKq2PkjbpES4=; b=qEvpYTmTfrKECiCN0IvpceXWT7oBMJyNb8HnKdet8q92cafWlUvXs0eK9B6ZCgNnkV tmiu60es/FTMizVTMt7pRACBvPXRN9nd0ZvHInEKiw5AMDvoAG6wMpvSGgCWKesi2U6c M48cZ1dCf16Nmnv+y7bU9Hv9tQi3JzkZm3kF1+E8eQawfQ4ZcX5LRoaJ++ltRbmGH3Ai uFwBEZfVTA4Ssll9j+OR9j77AHFXMe0nuyDR4TkMUl/rmRzfkhwNdTe5Hw9QQqdGq7nK 5ZhhZuFB3kZU38RXXhJ/rccB55Ib1dlENJjcSFyCo91awTRhuNtrp6v6YhGZ0HTiKvpe 2pUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804973; x=1690396973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vVW03ARTqWY9Do/0GxaVPJKlzSZSxWklKq2PkjbpES4=; b=YjW1Aj1qiAfhlSVQg6RxOIoEWfR24BJ0W0qk2UEEI5VOBb7n2VoSi4JYK0GJKjOaf1 tpUVLVHWgOnroPma8Exrh2rga1jgH+RouT9yt6nU2XoQVXZCh2yWncr/3mgZYuEde/rR 0kp1bAMaYTMK8f/oFgUF6+pTxL3RK4X2OaKoZPrmR2FU4AkQg6BplALIV2WeIDwMi0Qo uNIF71MViiDP1v5yOTSECoNUzG/VnFGb4TXbNsOlp8d+UVGJWOR1dWjhZ1VbHetFJYNN N92tS7+2Y932jR32Q5SeEPPbKDBn8+2hM/DKi/+kUDXT4c3GgeApb+RxRPdzIYTT8W2X QA7Q== X-Gm-Message-State: AC+VfDyzijelktd4SfyCuBehFEoGpOe3gcN2aUaV7DGdgj0VSGABNMfx GfFd0/vu3RZQwNLzL8yqodZFR1PyFV5NRTmXZHvUpQ== X-Google-Smtp-Source: ACHHUZ5sei8yL/enBNSLTtcGQFbLLTeKksvKKfbwHsCdn9fMQt4tAQ2tdDffJvup9Ow/O0qTTuHgEA== X-Received: by 2002:a17:90b:350e:b0:262:eb20:2dd8 with SMTP id ls14-20020a17090b350e00b00262eb202dd8mr5702704pjb.20.1687804973455; Mon, 26 Jun 2023 11:42:53 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h17-20020a17090adb9100b0024e37e0a67dsm4846577pjv.20.2023.06.26.11.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:42:53 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v4 3/5] eal: skip stdio on console logging Date: Mon, 26 Jun 2023 11:42:14 -0700 Message-Id: <20230626184223.155390-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626184223.155390-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230626184223.155390-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org There is no need to use stdio when logging to console. Using the write system call directly avoids unnecessary copy to stdio output buffer. Signed-off-by: Stephen Hemminger --- lib/eal/unix/eal_log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index d44416fd6570..baa721021991 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -19,8 +20,7 @@ console_log_write(__rte_unused void *c, const char *buf, size_t size) ssize_t ret; /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); + ret = write(STDERR_FILENO, buf, size); /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); From patchwork Mon Jun 26 18:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129007 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 820D642D5F; Mon, 26 Jun 2023 20:43:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C012B42D1D; Mon, 26 Jun 2023 20:42:58 +0200 (CEST) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mails.dpdk.org (Postfix) with ESMTP id 9952D42C4D for ; Mon, 26 Jun 2023 20:42:55 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-54f85f8b961so2840900a12.3 for ; Mon, 26 Jun 2023 11:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687804974; x=1690396974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G3wxp+uVKXBcYiMtKKmQyWepL34iCxOs75msWyk+ksk=; b=z4kmpef8ME/v3cMQPod8ra85iuV+CAJD2XOORPyNUchRPkp6j5KSIrqLkr4Aj+aFUJ avy1+MCk9ChMDkbUaQ5D5t99zVqAaXhejL07Agb/G4Sz6nWlZ3v4BiMIpqOiOcKPfVP3 jCBDwyTpzQywCGtuL2FmN0tQGthdkr70e1zVe4vw37efM6eUkxYzFhXbXKoT4AFujA9V wEtybrrYOPAZQZDzoBxmz4ZKEjCONn1Z9C8d/K3nCaURzrigvMp/zRpR8w37Q1ASC63i QsJgNe3QGLK/anWwTnji0lcSIlTinxr3lQZq1bSqvKyGhRGjiti3clAo7cRW27soSN8x +frw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804974; x=1690396974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G3wxp+uVKXBcYiMtKKmQyWepL34iCxOs75msWyk+ksk=; b=JZKLtGy2r2RF8csOmUgWtmjCISRWiXNBf0hwTj5MJ1RB7RwLctXyyIQpPu5gYXp1E8 x+rl7JBmVSG15Ta7oZJC8yJXQotXbToxsNV6Fh6VDAPiSenv7SAjZQ00M2+wJGxqxVi1 yIv3nl4CNQukWVworVo+rUQAzEkL9QHKrM73DheK3S0V8jLzkzW47SsTUv7l0WTrXoC7 +0FXEt6JesoW/E7lUAwBRGWeb94cpfAfAmHGAtIFZPfDfowos5X/N1SBQTE4ucNGN3rc vXRHEwX7IB2ihhFixYkz4Ck5hpZxyaUm3R/7QYqXQeD0PBolnaULqgVIej4xHNURb4kk xw3A== X-Gm-Message-State: AC+VfDwdkXyUHE0ERQTzl1HhU9q2cRHZuvyRyJIsj8eHICjMqAtiUVME f96y2J8XkeiYdkitR2n8eGp/tt76haac0uOkuigq5w== X-Google-Smtp-Source: ACHHUZ7Xts+0xG/tmxgoblotXY3UuPnSUWSouyGu7W8AQclVOeHQams8VaXQ21IETKK8AXpQYqR1LQ== X-Received: by 2002:a17:90a:190f:b0:258:9995:91cb with SMTP id 15-20020a17090a190f00b00258999591cbmr25158687pjg.49.1687804974487; Mon, 26 Jun 2023 11:42:54 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h17-20020a17090adb9100b0024e37e0a67dsm4846577pjv.20.2023.06.26.11.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:42:54 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v4 4/5] eal: move logging initialization earlier Date: Mon, 26 Jun 2023 11:42:15 -0700 Message-Id: <20230626184223.155390-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626184223.155390-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230626184223.155390-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The log stream should be setup before any messages. This ensures that any startup problems are captured on the syslog output, not only shown on the stderr. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 40 +++++++++++++++++++-------------------- lib/eal/linux/eal.c | 44 +++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 70087837da18..d3aac3d628a8 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -364,7 +364,7 @@ eal_get_hugepage_mem_size(void) return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; } -/* Parse the arguments for --log-level only */ +/* Parse the arguments for --log-level and --syslog */ static void eal_log_level_parse(int argc, char **argv) { @@ -386,20 +386,18 @@ eal_log_level_parse(int argc, char **argv) while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) + switch (opt) { + case OPT_SYSLOG_NUM: /* fallthrough */ + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + goto error; break; + case '?': + /* getopt is not happy, stop right now */ + goto error; + } } - +error: /* restore getopt lib */ optind = old_optind; optopt = old_optopt; @@ -437,8 +435,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -615,6 +613,12 @@ rte_eal_init(int argc, char **argv) /* set log level as early as possible */ eal_log_level_parse(argc, argv); + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + return -1; + } + if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; @@ -762,12 +766,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - return -1; - } - /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 60bb130aea15..51c4ec75d57b 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,7 +546,7 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ +/* Parse the arguments for --log-level and --syslog */ static void eal_log_level_parse(int argc, char **argv) { @@ -566,20 +566,18 @@ eal_log_level_parse(int argc, char **argv) while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) + switch (opt) { + case OPT_SYSLOG_NUM: /* fallthrough */ + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + goto error; break; + case '?': + /* getopt is not happy, stop right now */ + goto error; + } } - +error: /* restore getopt lib */ optind = old_optind; optopt = old_optopt; @@ -651,8 +649,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -997,6 +995,14 @@ rte_eal_init(int argc, char **argv) /* set log level as early as possible */ eal_log_level_parse(argc, argv); + if (eal_log_init(program_invocation_short_name, + internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); + return -1; + } + /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -1167,14 +1173,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); - return -1; - } - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) { rte_eal_init_alert("Cannot init VFIO"); From patchwork Mon Jun 26 18:42:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129008 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2C07142D5F; Mon, 26 Jun 2023 20:43:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ACBC342D2F; Mon, 26 Jun 2023 20:42:59 +0200 (CEST) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id D447C42D0C for ; Mon, 26 Jun 2023 20:42:56 +0200 (CEST) Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-262c6718d14so742169a91.2 for ; Mon, 26 Jun 2023 11:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687804976; x=1690396976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wMqTqBB9Kct1SM96bVI30Qu0Qv4SGifI7jxxJhBYRgo=; b=ljxsaqScTFbh/HDBEEulqjK9YVC2IFJPCiakV57yEwBNfrW0H9Kae8YljdcPMxWDn0 +sy77wrxF9Nz0kUEQSEShICn+bjHR1KxciUu6biqfZGoN/Z0EWuCZjXz8d4lnh3m8ewV V1Si0OpGNRJyoYZ6dKe5w3PWyJhNhjDVCor88JIfV3hlGlC6MJ5Z9S1IPPGRZ9Vhcw1S XUWct4VEklva95/J+NGsJJ97wTC1rNIAKb6S5vGu5gZqi7/dE0GcdFg/KAC9QgVLm8Cl pncOjzb2sArKCA1lZe8S9fL7v23ykuKoO569x216sqX5PZ16XhM2+WdVrc6BEAMzU6jZ YeNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804976; x=1690396976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wMqTqBB9Kct1SM96bVI30Qu0Qv4SGifI7jxxJhBYRgo=; b=Sw+DJAvU58Uc3Tftl8fccwiW7dbkY9GIq1sD/iROq4OnwK78eLKuA2HTCt59e5NM0A SDuxu3nEF5yOv3SmVzCXWu5ChJyDj9pagGdG0+3t6sV4HxpyfT7ihtXQ/8K8piD/cCRB 4SPe/Zz52NVJrRZkFVvoqW7zjdzgheKOmTRWJYoZnSagu7vjC58J2QQ3b0uQU4n7BHDl 69ND1w1tpmgnBTw8KREHyWbuRyt5YjNvzzOpCw/jCCosNecFc+HFXo5HogGwwHl87uIC FO6ibHMsUu7B04r8zVEAcC2oyMN3bYDxGDe1jxlWUxNmdxQcZBjPAMq2+A9hXLtBRRjg +P3w== X-Gm-Message-State: AC+VfDwcwan+2wvJo1SKpQdJknVQ93u7Dm8ee0wa43zYdaa3LVT1Hra6 EQgh8/BG7CkvfKFQCoOjU1YymwgQOgAOFfTlBOISRA== X-Google-Smtp-Source: ACHHUZ6NEPe4CcGoE+pdJ9FCylO0GQ/raJj8FiEREMurNsdy20UMwBWJ7vosrLjaLkx6bH1Hrwz0vA== X-Received: by 2002:a17:90a:19ca:b0:261:3202:3c4e with SMTP id 10-20020a17090a19ca00b0026132023c4emr6682108pjj.25.1687804975760; Mon, 26 Jun 2023 11:42:55 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h17-20020a17090adb9100b0024e37e0a67dsm4846577pjv.20.2023.06.26.11.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:42:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v4 5/5] eal: add option to put timestamp on console output Date: Mon, 26 Jun 2023 11:42:16 -0700 Message-Id: <20230626184223.155390-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626184223.155390-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230626184223.155390-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When debugging driver or startup issues, it is useful to have a timestamp on each message printed. The messages in syslog already have a timestamp, but often syslog is not available during testing. The timestamp format is chosen to look like the default Linux dmesg timestamp. Example: $ dpdk-testpmd --log-timestamp -- -i [ 0.007615] EAL: Detected CPU lcores: 16 [ 0.007657] EAL: Detected NUMA nodes: 1 [ 0.007878] EAL: Detected static linkage of DPDK [ 0.009469] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [ 0.012175] EAL: Selected IOVA mode 'VA' [ 0.120016] testpmd: No probed ethernet devices Interactive-mode selected [ 0.155959] testpmd: create a new mbuf pool : n=267456, size=2176, socket=0 [ 0.155990] testpmd: preferred mempool ops selected: ring_mp_mc Signed-off-by: Stephen Hemminger --- .../freebsd_gsg/freebsd_eal_parameters.rst | 5 +++ doc/guides/linux_gsg/linux_eal_parameters.rst | 5 +++ lib/eal/common/eal_common_options.c | 6 ++++ lib/eal/common/eal_internal_cfg.h | 3 ++ lib/eal/common/eal_options.h | 2 ++ lib/eal/freebsd/eal.c | 4 ++- lib/eal/linux/eal.c | 4 ++- lib/eal/unix/eal_log.c | 36 +++++++++++++++++-- 8 files changed, 61 insertions(+), 4 deletions(-) diff --git a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst index 9270d9fa3bfc..99cff10e963c 100644 --- a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst +++ b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst @@ -45,3 +45,8 @@ Other options local5 local6 local7 + +* ``--log-timestamp`` + + Add a timestamp of seconds and microseconds to each log message + written to standard output. diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f38139119..719ca6851625 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -135,3 +135,8 @@ Other options local5 local6 local7 + +* ``--log-timestamp`` + + Add a timestamp of seconds and microseconds to each log message + written to standard output. diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 03059336987d..c6c74cc31e9c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -76,6 +76,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_TIMESTAMP, 0, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, @@ -1835,6 +1836,10 @@ eal_parse_common_option(int opt, const char *optarg, } #ifndef RTE_EXEC_ENV_WINDOWS + case OPT_LOG_TIMESTAMP_NUM: + conf->log_timestamp = 1; + break; + case OPT_TRACE_NUM: { if (eal_trace_args_save(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" @@ -2194,6 +2199,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG" Set syslog facility\n" + " --"OPT_LOG_TIMESTAMP" Timestamp log output\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa79..1a1a7fdcfa8c 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -84,7 +84,10 @@ struct internal_config { /**< true if storing all pages within single files (per-page-size, * per-node) non-legacy mode only. */ + volatile uint8_t log_timestamp; /**< add timestamp to console output */ volatile int syslog_facility; /**< facility passed to openlog() */ + struct timespec log_start_time; /**< when logging was started */ + /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode; /** the shared VF token for VFIO-PCI bound PF and VFs devices */ diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb641284..cc9723868e3c 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index d3aac3d628a8..5c7cea8809bd 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -388,6 +388,7 @@ eal_log_level_parse(int argc, char **argv) switch (opt) { case OPT_SYSLOG_NUM: /* fallthrough */ + case OPT_LOG_TIMESTAMP_NUM: /* fallthrough */ case OPT_LOG_LEVEL_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) goto error; @@ -436,7 +437,8 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM || opt == OPT_LOG_LEVEL_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 51c4ec75d57b..051f9ad7f5bf 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -568,6 +568,7 @@ eal_log_level_parse(int argc, char **argv) switch (opt) { case OPT_SYSLOG_NUM: /* fallthrough */ + case OPT_LOG_TIMESTAMP_NUM: /* fallthrough */ case OPT_LOG_LEVEL_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) goto error; @@ -650,7 +651,8 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM || opt == OPT_LOG_LEVEL_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index baa721021991..f65a22612310 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -4,12 +4,15 @@ #include #include +#include #include +#include #include #include #include "eal_log.h" +#include "eal_private.h" /* * default log function @@ -17,10 +20,36 @@ static ssize_t console_log_write(__rte_unused void *c, const char *buf, size_t size) { + const struct internal_config *internal_conf = eal_get_internal_configuration(); ssize_t ret; - /* write on stderr */ - ret = write(STDERR_FILENO, buf, size); + /* add optional timestamp for stderr */ + if (internal_conf->log_timestamp) { + struct iovec iov[2]; + struct timespec ts; + char tbuf[64]; + + /* format up monotonic timestamp */ + clock_gettime(CLOCK_MONOTONIC, &ts); + ts.tv_sec -= internal_conf->log_start_time.tv_sec; + ts.tv_nsec -= internal_conf->log_start_time.tv_nsec; + if (ts.tv_nsec < 0) { + --ts.tv_sec; + ts.tv_nsec += 1000000000ul; + } + + /* use writev to put timestamp and buf in single operation */ + iov[0].iov_base = tbuf; + iov[0].iov_len = snprintf(tbuf, sizeof(tbuf), "[%8lu.%06lu] ", + ts.tv_sec, ts.tv_nsec / 1000u); + + /* casts are to unconstify the buf */ + iov[1].iov_base = (void *)(uintptr_t)buf; + iov[1].iov_len = size; + ret = writev(STDERR_FILENO, iov, 2); + } else { + ret = write(STDERR_FILENO, buf, size); + } /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); @@ -47,8 +76,11 @@ static cookie_io_functions_t console_log_func = { int eal_log_init(const char *id, int facility) { + struct internal_config *internal_conf = eal_get_internal_configuration(); FILE *log_stream; + clock_gettime(CLOCK_MONOTONIC, &internal_conf->log_start_time); + log_stream = fopencookie(NULL, "w+", console_log_func); if (log_stream == NULL) return -1;