From patchwork Mon Apr 28 12:40:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 885623 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C310826FA77; Mon, 28 Apr 2025 12:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745844019; cv=none; b=ZRTTjtN5otir5JHS4QIvvCkbwx0P8gGSHdxO1GUJrB/6FZNBfNQ7uJ0FIg7xtgFaWxjsCm+Sj8SO8X160xsjTUi/ABhL42caaK+mNxRb3w96gIhO1JvuHK1ZesX4NhmaTWwHT56krDnNoXWgdXXRwA+2rsp0I0bLeILtoOry4Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745844019; c=relaxed/simple; bh=uR1uMvXkwy1U5+i9SR6QfCR7GUaSyCdxeSM6QC/XKuI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MXGil2CRxqDFPf17TcMHoilDosMhMIUQSXu9n1+xxBraEMykt/i5z/ZvS26NIuA+hzbNV9YExgvSpsUJaH4feEbdP77cOniHuI/lughWXV16SjoNvEF5hhHKjsO9U7KW7cdcbhnbyU9Xq6BbO2gI9tzCYO9WoGQ7nkuTnuSStpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IAcLD5+S; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XwKjZS7C; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IAcLD5+S"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XwKjZS7C" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1745844016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3v9eG5lyR1SK4v03tlBXazUzZEzaRroYU5b0iRkhlHw=; b=IAcLD5+S6eZkQCbPl8qMeB1FvhwdYq3Fi5Alodl9KhQvVEShZ+4lSrUtZGA6LrmAMaIEYj UHXVJeWSBWcDXbxbePjp7FlWAMDGclDZzknLLVPoiQGwoAPw5dPtnO/wyC3BzZcEcE8dFN f6aKPtFvZ80bO7xpMB+gPkY3kso3qEDvrti+wqaBDBz3NyF77OZ+6HsDP2OPCHv7NQ1EMK BsXlphvpvb84iw691rpFMCtuesl/sXhwRIqD9gUVvcoo6yBg3r55DI+TdIJOOfMl5+WtbO jFnokUl/8O2uQIfT1rGDa3J5A3EPnml+jP9kIBzmu9TzWMC3kmgQeGyGOG80SQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1745844016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3v9eG5lyR1SK4v03tlBXazUzZEzaRroYU5b0iRkhlHw=; b=XwKjZS7CnuewFlLx5T3J//xJ8PMWgPbk1Lu9I49cR8+WX2nNpARew/EQeKPUA6wa95ZWRs ZVgsASIFmiHKRCBQ== Date: Mon, 28 Apr 2025 14:40:15 +0200 Subject: [PATCH v2 14/15] tools/nolibc: fall back to sys_clock_gettime() in gettimeofday() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250428-nolibc-misc-v2-14-3c043eeab06c@linutronix.de> References: <20250428-nolibc-misc-v2-0-3c043eeab06c@linutronix.de> In-Reply-To: <20250428-nolibc-misc-v2-0-3c043eeab06c@linutronix.de> To: Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1745844007; l=1463; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=uR1uMvXkwy1U5+i9SR6QfCR7GUaSyCdxeSM6QC/XKuI=; b=LeCfvd2ShVjqzQbWqsTNhYtwd85Lan7zthLtgUXXABK2wSuCCbELnNAtMTVPFJz0Ao7im5IBB UkJNRxJ86xjAo40zrYoxa6N5nYgJsgDfjanibZAfnTAoUXRaDkB7qYd X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Newer architectures (like riscv32) do not implement sys_gettimeofday(). In those cases fall back to sys_clock_gettime(). While that does not support the timezone argument of sys_gettimeofday(), specifying this argument invokes undefined behaviour, so it's safe to ignore. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/sys/time.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/sys/time.h b/tools/include/nolibc/sys/time.h index 785961c52fa3b6606ee30c19a4a1c11e86ccacc0..33782a19aae92907ccc636a656fc0f27b838dd61 100644 --- a/tools/include/nolibc/sys/time.h +++ b/tools/include/nolibc/sys/time.h @@ -13,6 +13,8 @@ #include "../arch.h" #include "../sys.h" +static int sys_clock_gettime(clockid_t clockid, struct timespec *tp); + /* * int gettimeofday(struct timeval *tv, struct timezone *tz); */ @@ -23,7 +25,18 @@ int sys_gettimeofday(struct timeval *tv, struct timezone *tz) #ifdef __NR_gettimeofday return my_syscall2(__NR_gettimeofday, tv, tz); #else - return __nolibc_enosys(__func__, tv, tz); + (void) tz; /* Non-NULL tz is undefined behaviour */ + + struct timespec tp; + int ret; + + ret = sys_clock_gettime(CLOCK_REALTIME, &tp); + if (!ret && tv) { + tv->tv_sec = tp.tv_sec; + tv->tv_usec = tp.tv_nsec / 1000; + } + + return ret; #endif }