From: Simon Horman <horms@kernel.org>
To: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
Cc: davem@davemloft.net, Liam.Howlett@oracle.com,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, jiri@resnulli.us,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
akpm@linux-foundation.org, shuah@kernel.org,
linux-kselftest@vger.kernel.org, peili.io@oracle.com
Subject: Re: [PATCH net-next 1/3] connector/cn_proc: Add hash table for threads
Date: Sat, 12 Oct 2024 10:43:52 +0100 [thread overview]
Message-ID: <20241012094352.GA77519@kernel.org> (raw)
In-Reply-To: <20241012004532.2071738-2-anjali.k.kulkarni@oracle.com>
On Fri, Oct 11, 2024 at 05:45:30PM -0700, Anjali Kulkarni wrote:
> Add a new type PROC_CN_MCAST_NOTIFY to proc connector API, which allows a
> thread to notify the kernel that it has exited abnormally. Thread can also
> send the exit status code it wants returned in the notification with it.
> Exiting thread can call this either when it wants to call pthread_exit()
> with non-zero value or from signal handler.
>
> Add a new file cn_hash.c which implements a hash table storing the exit
> codes of abnormally exiting threads, received by the system call above.
> The key used for the hash table is the pid of the thread, so when the
> thread actually exits, we lookup it's pid in the hash table and retrieve
> the exit code sent by user. If the exit code in struct task is 0, we
> then replace it with the user supplied non-zero exit code.
>
> cn_hash.c implements the hash table add, delete, lookup operations.
> mutex_lock() and mutex_unlock() operations are used to safeguard the
> integrity of the hash table while adding or deleting elements.
> connector.c has the API calls, called from cn_proc.c, as well as calls
> to allocate, initialize and free the hash table.
>
> Add a new flag in PF_* flags of task_struct - EXIT_NOTIFY. This flag is
> set when user sends the exit code via PROC_CN_MCAST_NOTIFY. While
> exiting, this flag is checked and the hash table add or delete calls
> are only made if this flag is set.
>
> A refcount field hrefcnt is added in struct cn_hash_dev, to keep track
> of number of threads which have added an entry in hash table. Before
> freeing the struct cn_hash_dev, this value must be 0.
>
> Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
...
> diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
> index 44b19e696176..8c6e002069d9 100644
> --- a/drivers/connector/cn_proc.c
> +++ b/drivers/connector/cn_proc.c
...
> @@ -326,9 +328,16 @@ void proc_exit_connector(struct task_struct *task)
> struct proc_event *ev;
> struct task_struct *parent;
> __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
> + __u32 uexit_code;
> + int err;
>
> - if (atomic_read(&proc_event_num_listeners) < 1)
> + if (atomic_read(&proc_event_num_listeners) < 1) {
> + if (likely(!(task->flags & PF_EXIT_NOTIFY)))
> + return;
> +
> + err = cn_del_elem(task->pid);
Hi Anjali,
err is set but otherwise unused in this function; probably it can be removed.
> return;
> + }
>
> msg = buffer_to_cn_msg(buffer);
> ev = (struct proc_event *)msg->data;
...
next prev parent reply other threads:[~2024-10-12 9:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-12 0:45 [PATCH net-next 0/3] Threads support in proc connector Anjali Kulkarni
2024-10-12 0:45 ` [PATCH net-next 1/3] connector/cn_proc: Add hash table for threads Anjali Kulkarni
2024-10-12 9:43 ` Simon Horman [this message]
2024-10-12 0:45 ` [PATCH net-next 2/3] connector/cn_proc: Kunit tests for threads hash table Anjali Kulkarni
2024-10-12 9:45 ` Simon Horman
2024-10-13 3:06 ` Anjali Kulkarni
2024-10-12 0:45 ` [PATCH net-next 3/3] connector/cn_proc: Selftest for threads Anjali Kulkarni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241012094352.GA77519@kernel.org \
--to=horms@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=anjali.k.kulkarni@oracle.com \
--cc=bsegall@google.com \
--cc=davem@davemloft.net \
--cc=dietmar.eggemann@arm.com \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=juri.lelli@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peili.io@oracle.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).