# Re: \[PATCH 4/4 v0.4\] sched/umcg: RFC: implement UMCG syscalls

- From: Thierry Delisle \<hidden\>
- Date: 2021-08-04 22:05:04 
- List: linux-api
- Page: https://ratatoskr.run/linux-api/2021/08/1468230
- Thread: https://ratatoskr.run/linux-api/2021/08/1464425/t.md

```text
I have attached an atomic stack implementation I wrote. I believe it would
be applicable here. It is very similar except the kernel side no longer
needs a retry loop, the looping is moved to the user-space after the pop.
Using it instead of the code you have in enqueue_idle_worker means the
timeout is no longer needed.

> - ``uint64_t idle_server_tid_ptr``: points to a pointer variable in the
>   userspace that points to an idle server, i.e. a server in IDLE state waiting
>   in sys_umcg_wait(); read-only; workers must have this field set; not used
>   in servers.
>
>   When a worker's blocking operation in the kernel completes, the kernel
>   changes the worker's state from ``BLOCKED`` to ``IDLE``, adds the worker
>   to the list of idle workers, and checks whether
>   ``*idle_server_tid_ptr`` is not zero. If not, the kernel tries to cmpxchg()
>   it with zero; if cmpxchg() succeeds, the kernel will then wake the server.
>   See `State transitions`_ below for more details.

In this case, I believe cmpxchg is not necessary and xchg suffices.

```

## Attachments

- [atomic\_stack.c](https://ratatoskr.run/linux-api/2021/08/1468230/attachment/0) (text/x-csrc, 3150 bytes)
