-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'linuxkerneltravel:develop' into develop
- Loading branch information
Showing
378 changed files
with
372,886 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CC = gcc | ||
CFLAGS = -Wall -Wextra | ||
LDFLAGS = -lrt | ||
|
||
.PHONY: all clean | ||
|
||
all: test_cpuwatcher sender receiver | ||
|
||
sender: mq_test_sender.c | ||
$(CC) $(CFLAGS) -o sender mq_test_sender.c $(LDFLAGS) | ||
|
||
receiver: mq_test_receiver.c | ||
$(CC) $(CFLAGS) -o receiver mq_test_receiver.c $(LDFLAGS) | ||
|
||
test_cpuwatcher: test_cpuwatcher.c | ||
$(CC) $(CFLAGS) -o test_cpuwatcher test_cpuwatcher.c | ||
clean: | ||
rm -f test_cpuwatcher sender receiver |
37 changes: 37 additions & 0 deletions
37
eBPF_Supermarket/CPU_Subsystem/cpu_watcher/test/mq_test_receiver.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <sys/stat.h> | ||
#include <mqueue.h> | ||
|
||
#define QUEUE_NAME "/test_queue" | ||
#define MSG_SIZE 50 | ||
|
||
int main() { | ||
mqd_t mq; | ||
char msg_buffer[MSG_SIZE]; | ||
unsigned int priority; | ||
|
||
// 打开消息队列 | ||
mq = mq_open(QUEUE_NAME, O_RDONLY); | ||
if (mq == (mqd_t)-1) { | ||
perror("mq_open"); | ||
exit(1); | ||
} | ||
|
||
// 接收消息 | ||
while (1) { | ||
if (mq_receive(mq, msg_buffer, MSG_SIZE, &priority) == -1) { | ||
perror("mq_receive"); | ||
break; | ||
} | ||
printf("Received: %s\n", msg_buffer); | ||
} | ||
|
||
// 关闭消息队列 | ||
mq_close(mq); | ||
|
||
return 0; | ||
} |
49 changes: 49 additions & 0 deletions
49
eBPF_Supermarket/CPU_Subsystem/cpu_watcher/test/mq_test_sender.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <sys/stat.h> | ||
#include <mqueue.h> | ||
|
||
#define QUEUE_NAME "/test_queue" | ||
#define MSG_SIZE 50 | ||
#define MAX_MSGS 10 | ||
|
||
int main() { | ||
mqd_t mq; | ||
struct mq_attr attr; | ||
char msg_buffer[MSG_SIZE]; | ||
unsigned int priority = 1; | ||
int i; | ||
|
||
// 设置消息队列属性 | ||
attr.mq_flags = 0; | ||
attr.mq_maxmsg = MAX_MSGS; | ||
attr.mq_msgsize = MSG_SIZE; | ||
attr.mq_curmsgs = 0; | ||
|
||
// 创建或打开消息队列 | ||
mq = mq_open(QUEUE_NAME, O_CREAT | O_WRONLY, 0644, &attr); | ||
if (mq == (mqd_t)-1) { | ||
perror("mq_open"); | ||
exit(1); | ||
} | ||
|
||
// 发送消息 | ||
for (i = 0;i<60 ; i++) { | ||
sprintf(msg_buffer, "Message %d", i); | ||
if (mq_send(mq, msg_buffer, strlen(msg_buffer) + 1, priority) == -1) { | ||
perror("mq_send"); | ||
break; | ||
} | ||
printf("Sent: %s\n", msg_buffer); | ||
sleep(1); | ||
} | ||
|
||
// 关闭消息队列 | ||
mq_close(mq); | ||
mq_unlink(QUEUE_NAME); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.