Skip to content

Conversation

@liujinhui-job
Copy link

@liujinhui-job liujinhui-job commented Jul 3, 2025

Add a Discrete Mode to select.‌

This mode is designed to optimize scenarios where ‌file descriptors (fds) are scattered‌ and the ‌smallest fd within the fdset is relatively large‌.
In such cases, it locates the smallest ‌user-defined fd‌ in the fastest possible manner, ‌instead of iterating from 0‌.
For loops can sometimes become a ‌significant performance bottleneck‌, especially in ‌non-blocking mode‌ with select.
While this mode ‌does not guarantee performance gains universally‌, it provides substantial improvement when the smallest user-defined fd is low (e.g., 32).
If the smallest fd is 1000, citp_ul_select ‌executes over 20 times faster‌ compared to the conventional iterative approach.

such as:

        (user first call open open open open ......)

        fd = socket(AF_INET, SOCK_STREAM, 0);  /* fd is 64 */

        FD_ZERO(&readfds);
        FD_SET(fd, &readfds);
        max_sd = fd;
        
        struct timeval timeout;
        timeout.tv_sec = 0;
        timeout.tv_usec = 0;

        activity = select(max_sd + 1, &readfds, NULL, NULL, &timeout);

The citp_ul_select function requires only two iterations to retrieve the user-configured value of fd 64.

@liujinhui-job liujinhui-job requested a review from a team as a code owner July 3, 2025 14:49
@ol-alexandra
Copy link
Contributor

Do you really have an application which uses select() in such a way? I used to believe that all "new" applications use poll or epoll, and the only use-case for select() is "a small application with 5 file descriptors". If you propose some complicated code, then this code should be tested (i.e. there should be a new test in Socket Tester https://github.com/Xilinx-CNS/cns-sapi-ts) and maintained (together with the tests). Is there any reason for adding such kind of code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants