xref: /dpdk/lib/eal/windows/eal_thread.c (revision a95d7054)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4 
5 #include <io.h>
6 
7 #include <rte_atomic.h>
8 #include <rte_debug.h>
9 #include <rte_launch.h>
10 #include <rte_lcore.h>
11 #include <rte_per_lcore.h>
12 #include <rte_common.h>
13 #include <rte_memory.h>
14 
15 #include "eal_private.h"
16 #include "eal_thread.h"
17 #include "eal_windows.h"
18 
19 void
eal_thread_wake_worker(unsigned int worker_id)20 eal_thread_wake_worker(unsigned int worker_id)
21 {
22 	int m2w = lcore_config[worker_id].pipe_main2worker[1];
23 	int w2m = lcore_config[worker_id].pipe_worker2main[0];
24 	char c = 0;
25 	int n;
26 
27 	do {
28 		n = _write(m2w, &c, 1);
29 	} while (n == 0 || (n < 0 && errno == EINTR));
30 	if (n < 0)
31 		rte_panic("cannot write on configuration pipe\n");
32 
33 	do {
34 		n = _read(w2m, &c, 1);
35 	} while (n < 0 && errno == EINTR);
36 	if (n <= 0)
37 		rte_panic("cannot read on configuration pipe\n");
38 }
39 
40 void
eal_thread_wait_command(void)41 eal_thread_wait_command(void)
42 {
43 	unsigned int lcore_id = rte_lcore_id();
44 	int m2w;
45 	char c;
46 	int n;
47 
48 	m2w = lcore_config[lcore_id].pipe_main2worker[0];
49 	do {
50 		n = _read(m2w, &c, 1);
51 	} while (n < 0 && errno == EINTR);
52 	if (n <= 0)
53 		rte_panic("cannot read on configuration pipe\n");
54 }
55 
56 void
eal_thread_ack_command(void)57 eal_thread_ack_command(void)
58 {
59 	unsigned int lcore_id = rte_lcore_id();
60 	char c = 0;
61 	int w2m;
62 	int n;
63 
64 	w2m = lcore_config[lcore_id].pipe_worker2main[1];
65 	do {
66 		n = _write(w2m, &c, 1);
67 	} while (n == 0 || (n < 0 && errno == EINTR));
68 	if (n < 0)
69 		rte_panic("cannot write on configuration pipe\n");
70 }
71 
72 /* function to create threads */
73 int
eal_thread_create(pthread_t * thread,unsigned int lcore_id)74 eal_thread_create(pthread_t *thread, unsigned int lcore_id)
75 {
76 	HANDLE th;
77 
78 	th = CreateThread(NULL, 0,
79 		(LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop,
80 						(LPVOID)(uintptr_t)lcore_id,
81 						CREATE_SUSPENDED,
82 						(LPDWORD)thread);
83 	if (!th)
84 		return -1;
85 
86 	SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
87 	SetThreadPriority(th, THREAD_PRIORITY_NORMAL);
88 
89 	if (ResumeThread(th) == (DWORD)-1) {
90 		(void)CloseHandle(th);
91 		return -1;
92 	}
93 
94 	return 0;
95 }
96 
97 /* get current thread ID */
98 int
rte_sys_gettid(void)99 rte_sys_gettid(void)
100 {
101 	return GetCurrentThreadId();
102 }
103 
104 int
rte_thread_setname(__rte_unused pthread_t id,__rte_unused const char * name)105 rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
106 {
107 	/* TODO */
108 	/* This is a stub, not the expected result */
109 	return 0;
110 }
111