From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC2E4C369DC for ; Tue, 29 Apr 2025 20:29:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 55F5410E096; Tue, 29 Apr 2025 20:29:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="JZRW9Fpo"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFD8710E096 for ; Tue, 29 Apr 2025 20:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745958563; x=1777494563; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version; bh=na8SeUPUh3STGbFrym+8gAp46ds6in/IZwgrB2aqC5w=; b=JZRW9FpoHvBVscqgXKO3XwJWwBVyjGufuDjKnNXyeyukCe55VE7bbWEc 5Aap6dwGGaFeejovd6egb1zfHEhRFnRIJlOQHWWtQHOJiwwCpTRWPRj+V hT8eiX8+XeJ9EqwYLxFzy5zFr72xmWRNnGex708hhh5B/QTxhB50P7odi r/DmeNBZKUCwaPE6y8QNg5XKbktnp9Nax9snH5VCMJspb5DhiZPpWU8BZ 5900puxmilZz+duaCbhWbmP9jmXQirCLYh1w52sbILsTlycc/pF1gjP7s vqm5tDbuORyscm8DXs6cbIIW76G3co9BhhCFJMMPIjwOHnynaOC+Us6uK Q==; X-CSE-ConnectionGUID: 6zNDqdE6SjGuExYW7R3Vgg== X-CSE-MsgGUID: HtNzLo9zQPm1b6cJBDKFeQ== X-IronPort-AV: E=McAfee;i="6700,10204,11418"; a="47691797" X-IronPort-AV: E=Sophos;i="6.15,250,1739865600"; d="scan'208";a="47691797" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2025 13:29:19 -0700 X-CSE-ConnectionGUID: NwP/oZyOSUubv+j0/+2BkQ== X-CSE-MsgGUID: gx7Ub0LeRxSyJThCYaPPPg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,250,1739865600"; d="scan'208";a="133836773" Received: from orsosgc001.jf.intel.com (HELO orsosgc001.intel.com) ([10.165.21.142]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2025 13:29:20 -0700 Date: Tue, 29 Apr 2025 13:29:19 -0700 Message-ID: <85wmb2r9sw.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Jeevaka Prabu Badrappan Cc: igt-dev@lists.freedesktop.org, sapna1.singh@intel.com, markyacoub@google.com, seanpaul@google.com, carlos.santa@intel.com Subject: Re: [PATCH 3/5] Avoid use of pthread_cancel by introducing an exit flag In-Reply-To: <20250429195745.40982-4-jeevaka.badrappan@intel.com> References: <20250429195745.40982-1-jeevaka.badrappan@intel.com> <20250429195745.40982-4-jeevaka.badrappan@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (x86_64-redhat-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" On Tue, 29 Apr 2025 12:57:43 -0700, Jeevaka Prabu Badrappan wrote: > > Android build fails due to pthread_cancel unavailability. > Replace pthread_cancel with thread exit based on an exit flag. How about adding the definition of pthread_cancel() in an android specific library and using that, rather than making changes here? I would think that approach might be better in general, calling into the android specific library, rather than using '#ifdef ANDROID' as seems to be done in other patches here? Thoughts? > > Signed-off-by: Jeevaka Prabu Badrappan > --- > lib/igt_dummyload.c | 6 +++--- > lib/igt_dummyload.h | 2 ++ > lib/xe/xe_spin.c | 2 +- > 3 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c > index 3cf80b762..38249afb7 100644 > --- a/lib/igt_dummyload.c > +++ b/lib/igt_dummyload.c > @@ -530,7 +530,7 @@ static void *timer_thread(void *data) > /* Wait until we see the timer fire, or we get cancelled */ > do { > read(spin->timerfd, &overruns, sizeof(overruns)); > - } while (!overruns); > + } while (!overruns && !spin->exit_thread); > > igt_spin_end(spin); > return NULL; > @@ -565,7 +565,7 @@ void igt_spin_set_timeout(igt_spin_t *spin, int64_t ns) > timerfd = timerfd_create(CLOCK_MONOTONIC, 0); > igt_assert(timerfd >= 0); > spin->timerfd = timerfd; > - > + spin->exit_thread = false; > pthread_attr_init(&attr); > pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); > pthread_attr_setschedpolicy(&attr, SCHED_FIFO); > @@ -631,7 +631,7 @@ void igt_spin_end(igt_spin_t *spin) > static void __igt_spin_free(int fd, igt_spin_t *spin) > { > if (spin->timerfd >= 0) { > - pthread_cancel(spin->timer_thread); > + spin->exit_thread = true; > igt_assert(pthread_join(spin->timer_thread, NULL) == 0); > close(spin->timerfd); > } > diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h > index b771011af..07b21227d 100644 > --- a/lib/igt_dummyload.h > +++ b/lib/igt_dummyload.h > @@ -26,6 +26,7 @@ > #define __IGT_DUMMYLOAD_H__ > > #include > +#include > #include > > #include "drmtest.h" > @@ -75,6 +76,7 @@ typedef struct igt_spin { > > struct timespec last_signal; > pthread_t timer_thread; > + atomic_bool exit_thread; > int timerfd; > > int out_fence; > diff --git a/lib/xe/xe_spin.c b/lib/xe/xe_spin.c > index a92903b6b..2fb688179 100644 > --- a/lib/xe/xe_spin.c > +++ b/lib/xe/xe_spin.c > @@ -264,7 +264,7 @@ void xe_spin_free(int fd, struct igt_spin *spin) > igt_assert(spin->driver == INTEL_DRIVER_XE); > > if (spin->timerfd >= 0) { > - pthread_cancel(spin->timer_thread); > + spin->exit_thread = true; > igt_assert(pthread_join(spin->timer_thread, NULL) == 0); > close(spin->timerfd); > } > -- > 2.49.0 >