From patchwork Tue Apr 16 21:52:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 789505 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8877F69946 for ; Tue, 16 Apr 2024 21:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304348; cv=none; b=Omm3xruEOsHVYE0QJ9XbR4VCagmP5yjDg/Mm9zXzLccgXZ4PwnUjKUUkRbry7z++3AADwXRxyTgsGOPOo5V0M/voru++XbV5vHFcHBExlWEUO8BRofb+pYeNVFPqADrlElk1nsFkOXci6S5JfpUpqEzNd280DYyXFBdK/Kb5Q1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304348; c=relaxed/simple; bh=wZgr20dfY+CkOzhOLyU4m7MU2TR5zJLdVN/TG6a7ASs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V1xJufBbDlxyibDyiejwBDkBw/cZ8wJANW4XpVx3/hLtRZuwl2mk3Jo4aAG+CeM23KgD214F/z9OdFuktZa7ae24ddBayPLw7O/9FbLbR352bDSnN+giduj/uZXCbIIRyLLE/mrH3OgOKti6AGgKPOG0nCJAhRZV/5FK00rQPVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=OfME08hP; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="OfME08hP" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ecf05fd12fso4643083b3a.2 for ; Tue, 16 Apr 2024 14:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1713304347; x=1713909147; darn=vger.kernel.org; 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=E7pba3IahTgD9DftxTzBcYMSbhG2YiMnuGqnb35n1gw=; b=OfME08hP/8joXdYaLOpI5zBOL4rYvM5Gv9V+LRV4neqNKZvyp7Aka+enWK+O5jwl/B XlCxA6gVaM2iDZVgBkEC4fwkjgmkrLfU+hZb//i3tN67RgzjMSzcgAfFilK5Gp5Fmgi2 Q+6ww/gIZGaNVuSHkzL72tRMriDkaj8JZMVMKF9LOm+9YAO33i89wgh57quYa3XGBWek eTfVnjVijDsX5LKe1FDtKlUI3WLnkr+mszDaSXoAgelf92TYBA2bvDmELDrR0rxjHHAN i7RP9bIkG5v00dspehOkP65QD1Na3ZKy+TZ0f5hF9FFiwbMQuf4lHVm5cfOAJ3CCdzz8 gDPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713304347; x=1713909147; 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=E7pba3IahTgD9DftxTzBcYMSbhG2YiMnuGqnb35n1gw=; b=atukZoVC7apYgAMbTjdj13Nah2c4HqdhnKc8QZ1PDxtc4tZhifuPVKK5pnjHIyejlZ fIcbRmzMVpfq/ctYX6mnIv8Rr2jDxM/rOX6QD7Nu0P5tiCtuBeFIznwwh/pM3aIPbs2U EG1dCs+mXyNoobsQjzJKFk7LKCPojITa3kj9+IK/xHQXo1VJBnLPUJcjvqAE0zlz50SW 269QI8UV1PNMXYZLYg9jSOBbfAN/eP033c8JOZsZQcex3OeDIi+4RUSh0Dnkh3/fZAhV EVENAXuRiLpexrEj0+LQLOzVZ+r49YIA3xuqcdPa0hD+L6/iK/q6rxKcWgfIR6Nh+U0i ifOg== X-Gm-Message-State: AOJu0YwQzCx1QTzWPZVyYlX2SlP9H6DloxpHgOWlIyZSPv83WnkXkvV7 ZIwMmyhpOngd73v2elh3xiazWLyz8zzpTQkpp3eH3uz4/JGx+e5TNBQlED44uNiwSfSE/rRH5gO bFSk= X-Google-Smtp-Source: AGHT+IGFIR9E16pOIAywVQvGIQs67h78S7XhPz1f7Q5RGYxP3YVap+9636Q5UhF1Pt+yT14zmGqrRg== X-Received: by 2002:a05:6a00:148a:b0:6ea:c04c:71cb with SMTP id v10-20020a056a00148a00b006eac04c71cbmr17655431pfu.3.1713304346785; Tue, 16 Apr 2024 14:52:26 -0700 (PDT) Received: from brgl-uxlite.. ([24.75.208.145]) by smtp.gmail.com with ESMTPSA id o8-20020a656148000000b005f07f34eb59sm8005217pgv.27.2024.04.16.14.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 14:52:25 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , =?utf-8?q?Gunnar_Th=C3=B6rnqvist?= Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH v2 1/4] tools: rename timeout to idle_timeout in gpiomon and gpionotify Date: Tue, 16 Apr 2024 23:52:19 +0200 Message-Id: <20240416215222.175166-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240416215222.175166-1-brgl@bgdev.pl> References: <20240416215222.175166-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use a more meaningful name for the variable storing the idle timeout value. Suggested-by: Kent Gibson Signed-off-by: Bartosz Golaszewski --- tools/gpiomon.c | 8 ++++---- tools/gpionotify.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/gpiomon.c b/tools/gpiomon.c index e3abb2d..40e6ac2 100644 --- a/tools/gpiomon.c +++ b/tools/gpiomon.c @@ -30,7 +30,7 @@ struct config { const char *fmt; enum gpiod_line_clock event_clock; int timestamp_fmt; - int timeout; + int idle_timeout; }; static void print_help(void) @@ -143,7 +143,7 @@ static int parse_config(int argc, char **argv, struct config *cfg) memset(cfg, 0, sizeof(*cfg)); cfg->edges = GPIOD_LINE_EDGE_BOTH; cfg->consumer = "gpiomon"; - cfg->timeout = -1; + cfg->idle_timeout = -1; for (;;) { optc = getopt_long(argc, argv, shortopts, longopts, &opti); @@ -176,7 +176,7 @@ static int parse_config(int argc, char **argv, struct config *cfg) cfg->fmt = optarg; break; case 'i': - cfg->timeout = parse_period_or_die(optarg) / 1000; + cfg->idle_timeout = parse_period_or_die(optarg) / 1000; break; case 'l': cfg->active_low = true; @@ -453,7 +453,7 @@ int main(int argc, char **argv) for (;;) { fflush(stdout); - ret = poll(pollfds, resolver->num_chips, cfg.timeout); + ret = poll(pollfds, resolver->num_chips, cfg.idle_timeout); if (ret < 0) die_perror("error polling for events"); diff --git a/tools/gpionotify.c b/tools/gpionotify.c index 2c56590..d2aee15 100644 --- a/tools/gpionotify.c +++ b/tools/gpionotify.c @@ -23,7 +23,7 @@ struct config { const char *chip_id; const char *fmt; int timestamp_fmt; - int timeout; + int idle_timeout; }; static void print_help(void) @@ -108,7 +108,7 @@ static int parse_config(int argc, char **argv, struct config *cfg) int opti, optc; memset(cfg, 0, sizeof(*cfg)); - cfg->timeout = -1; + cfg->idle_timeout = -1; for (;;) { optc = getopt_long(argc, argv, shortopts, longopts, &opti); @@ -132,7 +132,7 @@ static int parse_config(int argc, char **argv, struct config *cfg) cfg->fmt = optarg; break; case 'i': - cfg->timeout = parse_period_or_die(optarg) / 1000; + cfg->idle_timeout = parse_period_or_die(optarg) / 1000; break; case 'n': cfg->events_wanted = parse_uint_or_die(optarg); @@ -422,7 +422,7 @@ int main(int argc, char **argv) for (;;) { fflush(stdout); - ret = poll(pollfds, resolver->num_chips, cfg.timeout); + ret = poll(pollfds, resolver->num_chips, cfg.idle_timeout); if (ret < 0) die_perror("error polling for events"); From patchwork Tue Apr 16 21:52:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 790350 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34BD569946 for ; Tue, 16 Apr 2024 21:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304350; cv=none; b=JkR9qBtH+q8chM6AAzxta1kjVsxACV9kueYr0kXi+ev2g54KCbAu4/yZFV5rT0E3+d6IXYMw0hkL+D3xVE3cnJKaGWgTvblMGAscBLlzHFL6n8/33B/8JOvVTpbSzw88W9k+4g0PYGxlqD0NSPvbH5WVrL33PC7r1ucFxp3mayM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304350; c=relaxed/simple; bh=Xpo2ETpkTSXzES1cPuQ73Aak9SSPA5hN4hSxtPFO+E0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fjcWc7ZA9yjbOdKxYzSXhoDLBXXKum03XQJOLYbUZd5AIc4x6YpXKHG9h7A9vmUnihdOnlGVqgjTv39OjxMLW7KlIi1RpAUL+ZuqFkN13YvpYNeOWt4gdbBsq7B5beTclArM08WnN/LK0kYhi6rgr6FEU59CL7a0iui48LYNX/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=xc8v5d9j; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="xc8v5d9j" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6ed5109d924so4188621b3a.0 for ; Tue, 16 Apr 2024 14:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1713304348; x=1713909148; darn=vger.kernel.org; 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=ZUoEwV/WonERdygqJVUNKsyBTwb8gi0MTfMadGUK8J0=; b=xc8v5d9j1BK+yhWvBogEABIXDBgaLgQ8ITLd7EsTHKfJSmOs3+slFRMM/chs1/Za+3 5YZkhl6HIjnzekJA3JKDpFU3oAcxaEnn7INbQeXSduy4F5/Ru+xBaXdNDgH0OKQJ25UI MFsxEzkhz/4efyCHlZ9Lh60RbOQ31lpeuDoLNKWSwOcbjaqeuZqM2IKIPvjTRp9/NkAh J4y0ZFtA7lHHA+xXYzdKPF42bEen/eNvLHo3y399IG2SpeaYJvLNSjpOXS9Zi9em2Ist tV7AlHt1hlBPJxyAoJEXvw15bk8ZCm56siYNVo5kmYX2ZYxl/1dnWI9uwV5rZC6C9Qrf yKlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713304348; x=1713909148; 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=ZUoEwV/WonERdygqJVUNKsyBTwb8gi0MTfMadGUK8J0=; b=D5ppD8FD6jK9wYfygYbEZ+9lZclFr4Pr8rcaJy+dDDUoI+itE8qjN+88vmJdr+mteg UL/uAzr9WvXwyB4O41qumzeuXwzwctwya7Ds7KcyHHdPQkntqQEucYmV9HYvWwdb+nrQ 7xcPdGOvjcKhb6S30OvxV5JtfiGfxa34fwBUVfATTELnf7RxhrToOW7qziXKy6RcUAK4 79L0Y+/bRtzLSLmDfXvEXZaB1na+3TKlj3ONGNR7loWuAtmzr9DlF5NKA67HR98Cjhs8 jJqRI/oRDxM/BIBhwlTvz/2vMJ6uQYmyF8oiFySqy3dHEZPmv2cIVvfHSPFS9lpNUVOK HmrQ== X-Gm-Message-State: AOJu0YzM6CC5I9EWeLKQ9bP70TQXjtKiNcCtXaJZuAvmiWHZQt208a7D XJkDt6Jz8RoEBdjFJSfeFV5ItlgUaITzUlF19FRKHEyCZLTgmsGZBMJ1GA+///I= X-Google-Smtp-Source: AGHT+IEqnbIQNi207huXAQ8ctOL38JNw4GyD8GEfdN4/2489Qyp9aZRNzPKSh3bMbsxoP97/D/oPJA== X-Received: by 2002:a05:6a00:3cc4:b0:6ed:def8:4dc with SMTP id ln4-20020a056a003cc400b006eddef804dcmr15435623pfb.10.1713304348411; Tue, 16 Apr 2024 14:52:28 -0700 (PDT) Received: from brgl-uxlite.. ([24.75.208.145]) by smtp.gmail.com with ESMTPSA id o8-20020a656148000000b005f07f34eb59sm8005217pgv.27.2024.04.16.14.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 14:52:27 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , =?utf-8?q?Gunnar_Th=C3=B6rnqvist?= Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH v2 2/4] tools: use ppoll() where higher timeout resolution makes sense Date: Tue, 16 Apr 2024 23:52:20 +0200 Message-Id: <20240416215222.175166-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240416215222.175166-1-brgl@bgdev.pl> References: <20240416215222.175166-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski We allow timeout units to be specified in microseconds but for poll() we need to round them up to milliseconds. Switch to ppoll() to avoid losing precision. Signed-off-by: Bartosz Golaszewski --- tools/gpiomon.c | 12 ++++++++++-- tools/gpionotify.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/gpiomon.c b/tools/gpiomon.c index 40e6ac2..728a671 100644 --- a/tools/gpiomon.c +++ b/tools/gpiomon.c @@ -176,7 +176,7 @@ static int parse_config(int argc, char **argv, struct config *cfg) cfg->fmt = optarg; break; case 'i': - cfg->idle_timeout = parse_period_or_die(optarg) / 1000; + cfg->idle_timeout = parse_period_or_die(optarg); break; case 'l': cfg->active_low = true; @@ -362,6 +362,7 @@ int main(int argc, char **argv) int num_lines, events_done = 0; struct gpiod_edge_event *event; struct line_resolver *resolver; + struct timespec idle_timeout; struct gpiod_chip *chip; struct pollfd *pollfds; unsigned int *offsets; @@ -453,7 +454,14 @@ int main(int argc, char **argv) for (;;) { fflush(stdout); - ret = poll(pollfds, resolver->num_chips, cfg.idle_timeout); + if (cfg.idle_timeout > 0) { + idle_timeout.tv_sec = cfg.idle_timeout / 1000000; + idle_timeout.tv_nsec = + (cfg.idle_timeout % 1000000) * 1000; + } + + ret = ppoll(pollfds, resolver->num_chips, + cfg.idle_timeout > 0 ? &idle_timeout : NULL, NULL); if (ret < 0) die_perror("error polling for events"); diff --git a/tools/gpionotify.c b/tools/gpionotify.c index d2aee15..962896c 100644 --- a/tools/gpionotify.c +++ b/tools/gpionotify.c @@ -132,7 +132,7 @@ static int parse_config(int argc, char **argv, struct config *cfg) cfg->fmt = optarg; break; case 'i': - cfg->idle_timeout = parse_period_or_die(optarg) / 1000; + cfg->idle_timeout = parse_period_or_die(optarg); break; case 'n': cfg->events_wanted = parse_uint_or_die(optarg); @@ -374,6 +374,7 @@ int main(int argc, char **argv) int i, j, ret, events_done = 0, evtype; struct line_resolver *resolver; struct gpiod_info_event *event; + struct timespec idle_timeout; struct gpiod_chip **chips; struct gpiod_chip *chip; struct pollfd *pollfds; @@ -422,7 +423,14 @@ int main(int argc, char **argv) for (;;) { fflush(stdout); - ret = poll(pollfds, resolver->num_chips, cfg.idle_timeout); + if (cfg.idle_timeout > 0) { + idle_timeout.tv_sec = cfg.idle_timeout / 1000000; + idle_timeout.tv_nsec = + (cfg.idle_timeout % 1000000) * 1000; + } + + ret = ppoll(pollfds, resolver->num_chips, + cfg.idle_timeout > 0 ? &idle_timeout : NULL, NULL); if (ret < 0) die_perror("error polling for events"); From patchwork Tue Apr 16 21:52:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 790349 Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 306E86BFAB for ; Tue, 16 Apr 2024 21:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304353; cv=none; b=VOmfCLW5wlX0/iDRFGgU7zovyh0u43X1BCW2CvqYajaeVcCN4mTm0LmPK4cDWwoNQFiUHRo+WOcqYDN4rjvjOFH0/ML0XLMHE5kl//UQY+bjoDr0lt3aOgni0BZ8aAq3/FcizEX9jm67qf57xRcsD7ZJlj/EIEN21iDeztZEjQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304353; c=relaxed/simple; bh=FmZoPc2UXgA8hQ4F4ZNh77W/5ObFZOZybBTJ50S689g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=T6AntaFwlbC3x5GhDAk/Ck7v+Xa1bQv8x7dIb4diwtf6XDILXeJFgbd5KQma/UrvRiHcURj36Q5AD/SMn0wICDZczxKivBtK613qlMkQh4wZJgZr0NUJQdk91inrxGHiv6QJPrAL9VDOJ8gfq/QMhM3axWz4ljLDqhk9/z0VkZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=QlgfEazB; arc=none smtp.client-ip=209.85.166.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="QlgfEazB" Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-36b21e8c6ccso9481405ab.2 for ; Tue, 16 Apr 2024 14:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1713304350; x=1713909150; darn=vger.kernel.org; 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=ZB3bHTCzmJTzu2hQoCQM4n0k1utz0ffigFXp5Or7q7M=; b=QlgfEazBxONYU+FqiAXu/9RPyDOCRzhnnL/wbgR8Iat+wZqgMTrgcQ5CIqyUEnO+hi 83uuAL27jQhkvlPnlqW6FimlsNgXEOzu1T36Bq0JGZeifJZ6TBrIrLPVS/vtMayYqcH0 UyMIHvo7fQ+Ez1BktumC/DA8Mv+Q1Gp8BcChpghJGANvFCz2ftv1h5ChrnPNgR0M16hu p794PKwdcNwLlz7/eWVS0W/HirjKqTmRrIC4RTk/5iYzts4zbniXh6Am7rLU87nXTQt1 hpCWTNGMJGB7muhaLaNZcEPg1Fpw9UM2j2gObUtJhJbk58xJpYIbZnYhYTx7KYLdYIIH TgcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713304350; x=1713909150; 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=ZB3bHTCzmJTzu2hQoCQM4n0k1utz0ffigFXp5Or7q7M=; b=QPjhJTK8AEmRA28m2qWBXWukEwNTE3B8lo2/tc3Vz+I4Nu+pzMUk8mikGnG6xawWMn T6YYejFvFczJv2Nv1E7FUPZwYnPW8Ezc9LdAxHI+J49eN1hNxoePUZupA64YvfkleXan MmhZNbzfcQC6Ed6PxM4g0gKQVCcbxtrwM3nTgpwcnAnS4AI5t+qcHLMMzzzaai5XPxG+ PcAarm4RVrxAiOXz4t1c0cLf/jafKxVnuhS/4tY/mlYxMGFi2b1M5mKPfFpSItBqNoKv bDSZ8sOwN+Gen4M02QKn5loZITr5/py7CYfHkHEBVUfeOeVKPpqGoWdeBXE3Qz87qpeR q5Ow== X-Gm-Message-State: AOJu0YyM73u9Z54AsKce1cLsREMMQ73vw4jwV4E0o+4F+wrj7KMYItB+ PliD/XSTVU5FfXkuvTnCwIcwmoqlOZDNnqN2PLuAhMj4X+B5lTcB/p5p++3bRZQ= X-Google-Smtp-Source: AGHT+IFHDOj9GWio1hqxusecpY0Xx/dDFfjOzkFjNj2HvF1FFMy2gXF8Xrtf89jDLkYe9iR1h2yZbQ== X-Received: by 2002:a05:6e02:20e8:b0:368:c433:51db with SMTP id q8-20020a056e0220e800b00368c43351dbmr18627921ilv.23.1713304350168; Tue, 16 Apr 2024 14:52:30 -0700 (PDT) Received: from brgl-uxlite.. ([24.75.208.145]) by smtp.gmail.com with ESMTPSA id o8-20020a656148000000b005f07f34eb59sm8005217pgv.27.2024.04.16.14.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 14:52:28 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , =?utf-8?q?Gunnar_Th=C3=B6rnqvist?= Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH v2 3/4] tools: allow longer time periods Date: Tue, 16 Apr 2024 23:52:21 +0200 Message-Id: <20240416215222.175166-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240416215222.175166-1-brgl@bgdev.pl> References: <20240416215222.175166-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski We currently store time as microseconds in 32-bit integers and allow seconds as the longest time unit when parsing command-line arguments limiting the time period possible to specify when passing arguments such as --hold-period to 35 minutes. Let's use 64-bit integers to vastly increase that. Use nanosleep() instead of usleep() to extend the possible sleep time range. Reported-by: Gunnar Thörnqvist Signed-off-by: Bartosz Golaszewski --- configure.ac | 2 ++ tools/gpioget.c | 4 ++-- tools/gpiomon.c | 14 ++++++++++---- tools/gpionotify.c | 2 +- tools/gpioset.c | 16 ++++++++-------- tools/tools-common.c | 22 ++++++++++++++++------ tools/tools-common.h | 5 +++-- 7 files changed, 42 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index 3b5bbf2..a2370c5 100644 --- a/configure.ac +++ b/configure.ac @@ -120,6 +120,8 @@ AS_IF([test "x$with_tools" = xtrue], AC_CHECK_FUNC([asprintf], [], [FUNC_NOT_FOUND_TOOLS([asprintf])]) AC_CHECK_FUNC([scandir], [], [FUNC_NOT_FOUND_TOOLS([scandir])]) AC_CHECK_FUNC([versionsort], [], [FUNC_NOT_FOUND_TOOLS([versionsort])]) + AC_CHECK_FUNC([strtoull], [], [FUNC_NOT_FOUND_TOOLS([strtoull])]) + AC_CHECK_FUNC([nanosleep], [], [FUNC_NOT_FOUND_TOOLS([nanosleep])]) AS_IF([test "x$with_gpioset_interactive" = xtrue], [PKG_CHECK_MODULES([LIBEDIT], [libedit >= 3.1])]) ]) diff --git a/tools/gpioget.c b/tools/gpioget.c index f611737..bad7667 100644 --- a/tools/gpioget.c +++ b/tools/gpioget.c @@ -19,7 +19,7 @@ struct config { bool unquoted; enum gpiod_line_bias bias; enum gpiod_line_direction direction; - unsigned int hold_period_us; + unsigned long long hold_period_us; const char *chip_id; const char *consumer; }; @@ -205,7 +205,7 @@ int main(int argc, char **argv) die_perror("unable to request lines"); if (cfg.hold_period_us) - usleep(cfg.hold_period_us); + sleep_us(cfg.hold_period_us); ret = gpiod_line_request_get_values(request, values); if (ret) diff --git a/tools/gpiomon.c b/tools/gpiomon.c index 728a671..cf1857c 100644 --- a/tools/gpiomon.c +++ b/tools/gpiomon.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -24,13 +25,13 @@ struct config { enum gpiod_line_bias bias; enum gpiod_line_edge edges; int events_wanted; - unsigned int debounce_period_us; + unsigned long long debounce_period_us; const char *chip_id; const char *consumer; const char *fmt; enum gpiod_line_clock event_clock; int timestamp_fmt; - int idle_timeout; + long long idle_timeout; }; static void print_help(void) @@ -390,9 +391,14 @@ int main(int argc, char **argv) if (cfg.active_low) gpiod_line_settings_set_active_low(settings, true); - if (cfg.debounce_period_us) + if (cfg.debounce_period_us) { + if (cfg.debounce_period_us > UINT_MAX) + die("maximum debounce period is %uus, got %lluus", + UINT_MAX, cfg.debounce_period_us); + gpiod_line_settings_set_debounce_period_us( - settings, cfg.debounce_period_us); + settings, (unsigned long)cfg.debounce_period_us); + } gpiod_line_settings_set_event_clock(settings, cfg.event_clock); gpiod_line_settings_set_edge_detection(settings, cfg.edges); diff --git a/tools/gpionotify.c b/tools/gpionotify.c index 962896c..53bd1d0 100644 --- a/tools/gpionotify.c +++ b/tools/gpionotify.c @@ -23,7 +23,7 @@ struct config { const char *chip_id; const char *fmt; int timestamp_fmt; - int idle_timeout; + long long idle_timeout; }; static void print_help(void) diff --git a/tools/gpioset.c b/tools/gpioset.c index 863da4a..46dde07 100644 --- a/tools/gpioset.c +++ b/tools/gpioset.c @@ -28,8 +28,8 @@ struct config { enum gpiod_line_bias bias; enum gpiod_line_drive drive; int toggles; - unsigned int *toggle_periods; - unsigned int hold_period_us; + unsigned long long *toggle_periods; + unsigned long long hold_period_us; const char *chip_id; const char *consumer; }; @@ -94,10 +94,10 @@ static int parse_drive_or_die(const char *option) return 0; } -static int parse_periods_or_die(char *option, unsigned int **periods) +static int parse_periods_or_die(char *option, unsigned long long **periods) { int i, num_periods = 1; - unsigned int *pp; + unsigned long long *pp; char *end; for (i = 0; option[i] != '\0'; i++) @@ -376,7 +376,7 @@ static void toggle_all_lines(struct line_resolver *resolver) * and apply the values to the requests. * offset and values are scratch pads for working. */ -static void toggle_sequence(int toggles, unsigned int *toggle_periods, +static void toggle_sequence(int toggles, unsigned long long *toggle_periods, struct gpiod_line_request **requests, struct line_resolver *resolver, unsigned int *offsets, @@ -388,7 +388,7 @@ static void toggle_sequence(int toggles, unsigned int *toggle_periods, return; for (;;) { - usleep(toggle_periods[i]); + sleep_us(toggle_periods[i]); toggle_all_lines(resolver); apply_values(requests, resolver, offsets, values); @@ -826,7 +826,7 @@ static void interact(struct gpiod_line_request **requests, printf("invalid period: '%s'\n", words[1]); goto cmd_ok; } - usleep(period_us); + sleep_us(period_us); goto cmd_ok; } @@ -981,7 +981,7 @@ int main(int argc, char **argv) } if (cfg.hold_period_us) - usleep(cfg.hold_period_us); + sleep_us(cfg.hold_period_us); #ifdef GPIOSET_INTERACTIVE if (cfg.interactive) diff --git a/tools/tools-common.c b/tools/tools-common.c index 64592d3..500e9a2 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -112,12 +112,12 @@ int parse_bias_or_die(const char *option) return GPIOD_LINE_BIAS_DISABLED; } -int parse_period(const char *option) +long long parse_period(const char *option) { - unsigned long p, m = 0; + unsigned long long p, m = 0; char *end; - p = strtoul(option, &end, 10); + p = strtoull(option, &end, 10); switch (*end) { case 'u': @@ -147,15 +147,15 @@ int parse_period(const char *option) } p *= m; - if (*end != '\0' || p > INT_MAX) + if (*end != '\0' || p > LLONG_MAX) return -1; return p; } -unsigned int parse_period_or_die(const char *option) +unsigned long long parse_period_or_die(const char *option) { - int period = parse_period(option); + long long period = parse_period(option); if (period < 0) die("invalid period: %s", option); @@ -163,6 +163,16 @@ unsigned int parse_period_or_die(const char *option) return period; } +void sleep_us(unsigned long long period) +{ + struct timespec spec; + + spec.tv_sec = period / 1000000; + spec.tv_nsec = (period % 1000000) * 1000; + + nanosleep(&spec, NULL); +} + int parse_uint(const char *option) { unsigned long o; diff --git a/tools/tools-common.h b/tools/tools-common.h index c82317a..bc63080 100644 --- a/tools/tools-common.h +++ b/tools/tools-common.h @@ -87,8 +87,9 @@ void die(const char *fmt, ...) NORETURN PRINTF(1, 2); void die_perror(const char *fmt, ...) NORETURN PRINTF(1, 2); void print_version(void); int parse_bias_or_die(const char *option); -int parse_period(const char *option); -unsigned int parse_period_or_die(const char *option); +long long parse_period(const char *option); +unsigned long long parse_period_or_die(const char *option); +void sleep_us(unsigned long long period); int parse_uint(const char *option); unsigned int parse_uint_or_die(const char *option); void print_bias_help(void); From patchwork Tue Apr 16 21:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 789504 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14BDA69946 for ; Tue, 16 Apr 2024 21:52:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304353; cv=none; b=kDLf0cYvZDv5vtfXIlTQpUr/pTLoT2Z8k4YIL87bAWRckl76Qs9qvTTwurtRqeD8AxM/Q+i2AQcrF78Htinsm6LFEhKFhAd0iM5KzyvlT1mC4Kc19qJSCY7fXLR1Hv4itEs6aE+G0nFQesCFGl0irTlsxRpVLpAg+yJK3s4CnhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713304353; c=relaxed/simple; bh=q6/gLtyhQSyX7zsxFDwS1nDlm6kwyGd7DE1AAnd5Ks8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qwumieYJn88bcLhhk4KseiLKX5s/tVnfwVAQDpNIexk4rSHWjqPRm5nv52c42yFP8C92RYEoM09l4ohei4icLO2zJdHLpLFrAuPK+zM68T/46P9P8q7iU/1w7Qwgbv6RmZ81dCR+TBLTcI1/2oIch3AUrQyLkfOISuBFnc0gD9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=dq+jCISf; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="dq+jCISf" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6ed5109d924so4188665b3a.0 for ; Tue, 16 Apr 2024 14:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1713304351; x=1713909151; darn=vger.kernel.org; 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=TXiJdzRTAuB1UlX3lfsMbcreITp5HZxliXA/4a98Y64=; b=dq+jCISfnv29r/ddgXbGEF5TlyZL3tAtFSDg389/LE7B4UN60m8BUK7w6pKlaGiNh0 w67HmrWVcAat2iXZtXhs3v3ECblTQh1C5m0uFaspcCM9mLANKQKzCZSlJlnwoA0H0jml 4VKCh7JbdGHC/9F+GzKsNbmR9hNfeqY2MoHRACKucLH1jtrLUaMZsaHxmayoId7cCZ1Z UV9RlA6J9el2a0Qj31Zx7VGszBn7Q+QO2MSSajwZvXKEcqI8haXkhupnDOPkZNeNMhVH 9J29//xpm+VzgOdcKWIBQI1S2GIoBcooWdzcjCa1d/M0PCNuuznZg5JbYpcXNnIrYhd8 wlCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713304351; x=1713909151; 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=TXiJdzRTAuB1UlX3lfsMbcreITp5HZxliXA/4a98Y64=; b=jlNUa0pBVGNX3KwZT27HfmIPVu48Fcsb37JeQuyHaaE+v6saxzpwEbb/SGcSLQ1QCt Jq3f3GVOJXoUR1VyV7eZEQLbsxH0uem4bBbSJQju1IZ2lmRdUwirOndvbh3+IoZuT6/4 jEpek7uLuwir392kRTvPjqsDHWz4x1wh7hml0sba812pVmYJiiLwSmWFfaTXpuCEgyXo NC1GU3S0+KQFtxJrhirQSogBW5zGWe+59+6x6TTYBskmfUnpQ5NRVL4nklLnWM3Nzimv AfgidsD8UOcThRNJ89Ty24ri2LaY7wGenpi/EbobxMaojfOm1DGmrcxSD8w4eklarmwl Lukg== X-Gm-Message-State: AOJu0Yyb9EouDXZuxsaSRamtmmFqHR1xHzYAjxnkrPes6PMTLPxEiBGe /CuJTa4e1gfWUMJxEJ0PEV7GzFIuTPP2NJEbBfEz/gHwlvVWs1G0kOQiBZw5UyHPLbybZq6awC3 cyAw= X-Google-Smtp-Source: AGHT+IGAixADyk/tsrCZSC2YS7wzRIrpN+S1hZwAxxKZOgoLJcJBlwxtj5tmxfZm0fYIiUdmxF9OvQ== X-Received: by 2002:a05:6a21:3d84:b0:1a7:aba5:7ce9 with SMTP id bj4-20020a056a213d8400b001a7aba57ce9mr12798568pzc.34.1713304351505; Tue, 16 Apr 2024 14:52:31 -0700 (PDT) Received: from brgl-uxlite.. ([24.75.208.145]) by smtp.gmail.com with ESMTPSA id o8-20020a656148000000b005f07f34eb59sm8005217pgv.27.2024.04.16.14.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 14:52:30 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Kent Gibson , =?utf-8?q?Gunnar_Th=C3=B6rnqvist?= Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH v2 4/4] tools: add minutes as a new supported time unit Date: Tue, 16 Apr 2024 23:52:22 +0200 Message-Id: <20240416215222.175166-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240416215222.175166-1-brgl@bgdev.pl> References: <20240416215222.175166-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Make it more convenient to specify longer time periods in gpio-tools by introducing minutes as the new time unit. Signed-off-by: Bartosz Golaszewski --- tools/tools-common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/tools-common.c b/tools/tools-common.c index 500e9a2..4340bce 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -138,10 +138,12 @@ long long parse_period(const char *option) } if (m) { - if (*end != 's') + if (*end == '\0') + m = 60000000; + else if (*end == 's') + end++; + else return -1; - - end++; } else { m = 1000; } @@ -213,7 +215,7 @@ void print_period_help(void) { printf("\nPeriods:\n"); printf(" Periods are taken as milliseconds unless units are specified. e.g. 10us.\n"); - printf(" Supported units are 's', 'ms', and 'us'.\n"); + printf(" Supported units are 'm', 's', 'ms', and 'us' for minutes, seconds, milliseconds and microseconds respectively.\n"); } #define TIME_BUFFER_SIZE 20