From 09e2dc8e3fdbd6a4ffda1b2751f022dc156e09d2 Mon Sep 17 00:00:00 2001 From: Rolf Bork <rbork@caltech.edu> Date: Fri, 10 Apr 2020 14:45:33 -0500 Subject: [PATCH] Got rid of old gm and rtai code that is no longer used. --- src/fe/gm_rcvr/Makefile | 37 --- src/fe/gm_rcvr/gm_rcvr.c | 64 ----- src/fe/gm_rcvr/manage_network.c | 114 --------- src/fe/rtai_shmem/GNUmakefile | 26 -- src/fe/rtai_shmem/Makefile | 37 --- src/fe/rtai_shmem/run | 17 -- src/fe/rtai_shmem/setup_shmem.c | 32 --- src/fe/shmem/Makefile | 19 -- src/fe/shmem/setup_shmem.c | 104 -------- src/fe/test/gm_direct.c | 343 --------------------------- src/fe/test/gm_simple_example.h | 43 ---- src/fe/test/gm_simple_example_recv.c | 317 ------------------------- src/fe/test/gm_simple_example_send.c | 320 ------------------------- 13 files changed, 1473 deletions(-) delete mode 100644 src/fe/gm_rcvr/Makefile delete mode 100644 src/fe/gm_rcvr/gm_rcvr.c delete mode 100644 src/fe/gm_rcvr/manage_network.c delete mode 100644 src/fe/rtai_shmem/GNUmakefile delete mode 100644 src/fe/rtai_shmem/Makefile delete mode 100755 src/fe/rtai_shmem/run delete mode 100644 src/fe/rtai_shmem/setup_shmem.c delete mode 100644 src/fe/shmem/Makefile delete mode 100644 src/fe/shmem/setup_shmem.c delete mode 100644 src/fe/test/gm_direct.c delete mode 100644 src/fe/test/gm_simple_example.h delete mode 100644 src/fe/test/gm_simple_example_recv.c delete mode 100644 src/fe/test/gm_simple_example_send.c diff --git a/src/fe/gm_rcvr/Makefile b/src/fe/gm_rcvr/Makefile deleted file mode 100644 index 8c66b6994..000000000 --- a/src/fe/gm_rcvr/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# RTLinux makefile -include /opt/rtldk-2.2/rtlinuxpro/rtl.mk - - -TARGET_RTL := gm_rcvr.rtl -LIBRARY_OBJS := myri.o fb.o manage_network.o -LDFLAGS_$(TARGET_RTL) := -g $(LIBRARY_OBJS) - -$(TARGET_RTL): $(LIBRARY_OBJS) - -gm_rcvr.o: gm_rcvr.c - $(CC) $(CFLAGS) -c $< -o $@ -myri.o: ../myri.c - $(CC) $(CFLAGS) -D__KERNEL__ -c $< -fb.o: ../fb.c - $(CC) $(CFLAGS) -D__KERNEL__ -c $< -manage_network.o: manage_network.c - $(CC) $(CFLAGS) -D__KERNEL__ -c $< - -ALL += user_mmap $(TARGET_RTL) -CFLAGS += -I../../include -CFLAGS += -I/opt/gm/include -CFLAGS += -DSERVO2K -CFLAGS += -DSAS_CODE -CFLAGS += -D_ADVANCED_LIGO=1 -CFLAGS += -DUSE_GM=1 -CFLAGS += -g -#CFLAGS += -DNO_SYNC -#CFLAGS += -DNO_DAQ - -all: $(ALL) - -clean: - rm -f $(ALL) *.o - -include /opt/rtldk-2.2/rtlinuxpro/Rules.make - diff --git a/src/fe/gm_rcvr/gm_rcvr.c b/src/fe/gm_rcvr/gm_rcvr.c deleted file mode 100644 index d6f16a355..000000000 --- a/src/fe/gm_rcvr/gm_rcvr.c +++ /dev/null @@ -1,64 +0,0 @@ -#include <rtl_time.h> -#include <time.h> -#include <fcntl.h> -#include <pthread.h> -#include <unistd.h> -#include <sys/mman.h> -#include <stdio.h> -#include <drv/myri.h> -#include <drv/gmnet.h> - -#define MMAP_SIZE 1024*1024*64-5000 - -extern void *manage_network(void *); -extern int stop_net_manager; - -unsigned char *_ipc_shm; - -int main(int argc, char **argv) -{ - int wfd; - char *file_name = "/rtl_mem_ipc"; - - wfd = shm_open(file_name, RTL_O_RDWR, 0666); - if (wfd == -1) { - printf("open r/w failed on %s (%d)\n", file_name, errno); - rtl_perror("shm_open()"); - return -1; - } - _ipc_shm = (unsigned char *)rtl_mmap(NULL,MMAP_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,wfd,0); - if (_ipc_shm == MAP_FAILED) { - printf("mmap failed for IPC shared memory area\n"); - rtl_perror("mmap()"); - return -1; - } - - /* Open Myrinet */ - if (myriNetInit(-1) != 1) return 1; - -#if 0 - /* Register IPC memory; Only first 4K are registered */ - gm_status_t status = gm_register_memory(netPort, _ipc_shm, GM_PAGE_LEN); - if (status != GM_SUCCESS) { - printk ("Couldn't register memory for DMA; error=%d", status); - return 0; - } -#endif - - - /* create the thread */ - rtl_pthread_t thread; - pthread_create(&thread, NULL, manage_network, 0); - - /* wait for us to be removed or killed */ - rtl_main_wait(); - stop_net_manager = 1; - rtl_pthread_cancel(thread); - rtl_pthread_join(thread, NULL); - - //gm_deregister_memory(netPort, _ipc_shm, GM_PAGE_LEN); - - myriNetClose(); - - return 0; -} diff --git a/src/fe/gm_rcvr/manage_network.c b/src/fe/gm_rcvr/manage_network.c deleted file mode 100644 index 4848c36c7..000000000 --- a/src/fe/gm_rcvr/manage_network.c +++ /dev/null @@ -1,114 +0,0 @@ -#include <linux/types.h> -#include <linux/pci.h> -#include <asm/io.h> -#include <asm/uaccess.h> -#include <drv/gmnet.h> -#include <drv/myri.h> -#include <rtl_time.h> - -int stop_net_manager = 0; -extern unsigned char *_ipc_shm; - -typedef struct -{ - int messages_expected; - int callbacks_pending; -} gm_s_e_context_t; - -gm_s_e_context_t context; - -static void -my_send_callback (struct gm_port *port, void *the_context, - gm_status_t the_status) -{ - /* One pending callback has been received */ - ((gm_s_e_context_t *)the_context)->callbacks_pending--; - - switch (the_status) - { - case GM_SUCCESS: - break; - - case GM_SEND_DROPPED: - printk ("**** Send dropped!\n"); - break; - - default: - printk ("Send completed with error %d", the_status); - } -} - - -void *manage_network(void *foo) -{ - gm_s_e_id_message_t *id_message; - - gm_u32_t my_node_id; - unsigned int my_global_id = 0; - gm_get_node_id (netPort, &my_node_id); - gm_status_t status = gm_node_id_to_global_id (netPort, my_node_id, &my_global_id); - if (status != GM_SUCCESS) { - printk ("Couldn't convert node ID to global ID; error=%d", status); - return 0; - } - - /* FIXME: Program appears to crash badly on a 4-way x86_64 system */ - /* Since I can't register shared memory, I can't use this program */ - /* Register IPC memory; Only first 4K are registered */ - status = gm_register_memory(netPort, _ipc_shm, GM_PAGE_LEN); - if (status != GM_SUCCESS) { - printk ("Couldn't register memory for DMA; error=%d", status); - return 0; - } - - /* Allocate message buffer */ - id_message = (gm_s_e_id_message_t *)gm_dma_calloc (netPort, 1, sizeof(gm_s_e_id_message_t)); - if (id_message == 0) { - printk ("Couldn't allocate output buffer for id_message\n"); - return 0; - } - - id_message->directed_recv_buffer_addr = gm_hton_u64((gm_size_t)_ipc_shm); - id_message->global_id = gm_hton_u32(my_global_id); - - /* Receive messages */ - for (;!stop_net_manager;) { - gm_recv_event_t *event = gm_receive (netPort); - switch (GM_RECV_EVENT_TYPE(event)) { - case GM_RECV_EVENT: - case GM_HIGH_RECV_EVENT: - { - daqMessage *rcvData = (daqMessage *)gm_ntohp(event->recv.buffer); - if (rcvData == 0) { - printk("Received zero pointer!\n"); - break; - } - if (strcmp(rcvData->message,"STT") == 0) { - gm_u32_t node_id = gm_ntoh_u16(event->recv.sender_node_id); - int dcuId = ntohl(rcvData->dcuId); - printk("Recv'd init from dcuId = %d GM node id %d\n", dcuId, node_id); - // Send back the id_message, which includes the DMA memory address info - gm_send_with_callback (netPort, - id_message, - GM_RCV_MESSAGE_SIZE, - sizeof(gm_s_e_id_message_t), - GM_DAQ_PRIORITY, - node_id, - GM_PORT_NUM_SEND, - my_send_callback, - &context); - context.callbacks_pending++; - } - } - case GM_NO_RECV_EVENT: - break; - default: - // This is where sent message callbacks go - gm_unknown (netPort, event); /* gm_unknown calls the callback */ - } - rtl_usleep(100000); - } - - gm_dma_free (netPort, id_message); - return 0; -} diff --git a/src/fe/rtai_shmem/GNUmakefile b/src/fe/rtai_shmem/GNUmakefile deleted file mode 100644 index 686a63db1..000000000 --- a/src/fe/rtai_shmem/GNUmakefile +++ /dev/null @@ -1,26 +0,0 @@ -# RTAI Makeflie - -prefix := $(shell rtai-config --prefix) - -ifeq ($(prefix),) -$(error Please add <rtai-install>/bin to your PATH variable) -endif - -ARCH = $(shell rtai-config --arch) -# If an arch-dependent dir is found, process it too. -ARCHDIR = $(shell test -d $(ARCH) && echo $(ARCH) || echo) - -CC = $(shell rtai-config --cc) - -LXRT_CFLAGS = $(shell rtai-config --lxrt-cflags) -LINUX_DIR = $(shell rtai-config --linux-dir) - - -all:: - $(MAKE) -C $(LINUX_DIR) CC=$(CC) SUBDIRS=$$PWD V=$(V) modules -# @if test -e $(LINUX_DIR)/Module.symvers; then mv -f $(LINUX_DIR)/Module.symvers $(LINUX_DIR)/__Module.symvers; fi; if test -e $(LINUX_DIR)/vmlinux; then mv -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/__vmlinux; fi; \ - $(MAKE) -C $(LINUX_DIR) CC=$(CC) SUBDIRS=$$PWD V=$(V) modules \ - && if test -e $(LINUX_DIR)/__Module.symvers; then mv -f $(LINUX_DIR)/__Module.symvers $(LINUX_DIR)/Module.symvers; fi && if test -e $(LINUX_DIR)/__vmlinux; then mv -f $(LINUX_DIR)/__vmlinux $(LINUX_DIR)/vmlinux; fi - -clean:: - $(RM) $(LINUX_DIR)/.tmp_versions/*_rt.mod *.o *.ko *.mod.c .*.cmd diff --git a/src/fe/rtai_shmem/Makefile b/src/fe/rtai_shmem/Makefile deleted file mode 100644 index 2d3a98b45..000000000 --- a/src/fe/rtai_shmem/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# Real Time Application Interface - -LDFLAGS_$(TARGET_RTL) := -g $(LIBRARY_OBJS) - -$(TARGET_RTL): $(LIBRARY_OBJS) - -setup_shmem.o: setup_shmem.c - $(CC) $(CFLAGS) -c $< -o $@ - -EXTRA_CFLAGS += -DRTAI=1 -EXTRA_CFLAGS += -I$(SUBDIRS)/../../include -#EXTRA_CFLAGS += -I/opt/gm/include -EXTRA_CFLAGS += -DSERVO32K -EXTRA_CFLAGS += -DOMC_CODE -EXTRA_CFLAGS += -D_ADVANCED_LIGO=1 -EXTRA_CFLAGS += -g -#Comment out to enable 1PPS synchronization -EXTRA_CFLAGS += -DNO_SYNC -#Uncomment to disable DAQ and testpoints -EXTRA_CFLAGS += -DNO_DAQ -#Uncomment to enable local frame builder; comment out USE_GM setting too -EXTRA_CFLAGS += -DSHMEM_DAQ -#EXTRA_CFLAGS += -DUSE_GM=1 -#Comment out to stop A/D oversampling -EXTRA_CFLAGS += -DOVERSAMPLE -#Comment out to stop interpolating D/A outputs -EXTRA_CFLAGS += -DOVERSAMPLE_DAC -#Comment out to disable initial LIGO compatibility -EXTRA_CFLAGS += -DCOMPAT_INITIAL_LIGO -#Uncomment to run on a specific CPU -#EXTRA_CFLAGS += -DSPECIFIC_CPU=2 - -EXTRA_CFLAGS += $(shell rtai-config --module-cflags) -I/usr/include -ffast-math - -obj-m += setup_shmem.o - -#setup_shmem-objs := setup_shmem.o diff --git a/src/fe/rtai_shmem/run b/src/fe/rtai_shmem/run deleted file mode 100755 index b263fb483..000000000 --- a/src/fe/rtai_shmem/run +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -if [ $UID != 0 ]; then SUDO="sudo "; else SUDO=""; fi -echo -echo "*** Simple RTAI SHM demo (kernel) ***" -echo "Press <enter> to load modules:" -read junk -cd ..; sudo ./ldmod; cd - -echo -echo "Now start the realtime process <enter>, <ctrl-C> to end it." -read junk -sync -sudo /sbin/insmod ./setup_shmem.ko; -#./display -echo -echo "Done. Press <enter> to remove the modules." -read junk -./rem diff --git a/src/fe/rtai_shmem/setup_shmem.c b/src/fe/rtai_shmem/setup_shmem.c deleted file mode 100644 index 6c7ec82e6..000000000 --- a/src/fe/rtai_shmem/setup_shmem.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <rtai.h> -#include <rtai_sched.h> -#include <rtai_shm.h> -#include <rtai_nam2num.h> - -MODULE_DESCRIPTION("Create OM1 shared memory"); -MODULE_AUTHOR("Alex Ivanov<aivanov@ligo.caltech.edu>"); -MODULE_LICENSE("GPL"); - -static char *sysname = "om1"; -static char *sysname_daq = "om1_daq"; -#define MMAP_SIZE 1024*1024*64 - -int init_module() { - // Allocate FE to Epics comm area - void *addr = rtai_kmalloc(nam2num(sysname), MMAP_SIZE); - printk("nam2num(%s)=%d; returned addr = 0x%x\n", sysname, nam2num(sysname), addr); - // Allocate FE DAQ area - addr = rtai_kmalloc(nam2num(sysname_daq), MMAP_SIZE); - printk("nam2num(%s)=%d; returned addr = 0x%x\n", sysname_daq, nam2num(sysname), addr); - // Allocate IPC area - rtai_kmalloc(nam2num("ipc"), MMAP_SIZE); - return 0; -} -void cleanup_module (void) { - rtai_kfree(nam2num(sysname)); - rtai_kfree(nam2num(sysname_daq)); - rtai_kfree(nam2num("ipc")); -} diff --git a/src/fe/shmem/Makefile b/src/fe/shmem/Makefile deleted file mode 100644 index 11d97cc44..000000000 --- a/src/fe/shmem/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# RTLinux makefile -include /opt/rtldk-2.2/rtlinuxpro/rtl.mk -#include /home/controls/common_pc_64_build/build/rtcore-base-5.1/rtl.mk - - -TARGET_RTL := setup_shmem.rtl -LIBRARY_OBJS := map.o - -ALL += setup_shmem.rtl -CFLAGS += -I../../include -DRTL_BUILD - -all: $(ALL) - -clean: - rm -f $(ALL) *.o - -include /opt/rtldk-2.2/rtlinuxpro/Rules.make -#include /home/controls/common_pc_64_build/build/rtcore-base-5.1/Rules.make - diff --git a/src/fe/shmem/setup_shmem.c b/src/fe/shmem/setup_shmem.c deleted file mode 100644 index 3f7fcc019..000000000 --- a/src/fe/shmem/setup_shmem.c +++ /dev/null @@ -1,104 +0,0 @@ -#include <time.h> -#include <fcntl.h> -#include <pthread.h> -#include <unistd.h> -#include <sys/mman.h> -#include <stdio.h> - -#define MMAP_SIZE 1024*1024*64-5000 - - -/* How many systems configured */ -int sys_count = 0; - -/* Systems information (configuration) */ -struct sys_info{ - char name[128]; /* System name */ - int adcs; /* ADC boards count */ - int dacs; /* DAC board count */ -} sys_info[128]; - -char * -get_fname(int s) { - static char fname[128] = "/rtl_epics"; - switch (sys_count) { - case 0: - break; - default: - sprintf(fname, "/rtl_mem_%s", sys_info[s].name); - break; - } - return fname; -} - -/* ./setup_shmem.rtl 'das,adc=1,dac=1' 'pde,adc=1,dac=1' */ - -int main(int argc, char **argv) -{ - int cnt, i; - sys_count = 0; - memset(sys_info, 0, sizeof(sys_info)); - - if (argc > 1) { - for (i = 0; i < argc-1; i++) { - strcpy(sys_info[i].name, argv[i+1]); - sys_info[i].adcs = 1; - sys_info[i].dacs = 0; - sys_info[argc-1+i] = sys_info[i]; - strcat(sys_info[argc-1+i].name, "_daq"); - } - sys_count = argc - 1; - sys_count *= 2; - } - /* Add IPC area */ - strcpy(sys_info[sys_count].name, "ipc"); - sys_info[sys_count].adcs = 1; - sys_info[sys_count].dacs = 0; - sys_count += 1; -#if 0 - for (i = 0; i < sys_count; i++) { - printf("%s: adcs=%d, dacs=%d\n", sys_info[i].name, sys_info[i].adcs, sys_info[i].dacs); - } -#endif - - cnt = sys_count; - if (cnt == 0) cnt = 1; - -#if defined(RTL_BUILD) - for (i = 0; i < cnt; i++) { - int wfd; - /* - * Create the shared memory area. By passing a non-zero value - * for the mode, this means we also create a node in the GPOS. - */ - char *file_name = get_fname(i); - wfd = shm_open(file_name, RTL_O_CREAT, 0666); - if (wfd == -1) { - printf("open failed for write on %s (%d)\n", file_name, errno); - rtl_perror("shm_open()"); - return -1; - } - - /* Set the shared area to the right size */ - if (0 != ftruncate(wfd,MMAP_SIZE)) { - printf("ftruncate failed (%d)\n",errno); - rtl_perror("ftruncate()"); - return -1; - } - - close(wfd); - } - - /* wait for us to be removed or killed */ - rtl_main_wait(); - - /* Note that this is a shared area created with shm_open() - we close - * it with close(), but use shm_unlink() to actually destroy the area - */ - for (i = 0; i < cnt; i++) { - shm_unlink(get_fname(i)); - } -#endif - - return 0; -} diff --git a/src/fe/test/gm_direct.c b/src/fe/test/gm_direct.c deleted file mode 100644 index 445408870..000000000 --- a/src/fe/test/gm_direct.c +++ /dev/null @@ -1,343 +0,0 @@ -/* test gm_direct_send() latency */ -#include <stdio.h> -#include <rtl_time.h> -#include <fcntl.h> -#include <pthread.h> -#include <unistd.h> -#include <sys/mman.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "msr.h" - -#include <drv/gmnet.h> - -/* gm receiver host name */ -char receiver_nodename[64]; - -/* if we are running in slave mode */ -int slave = 0; - -#define CPU_RATE 2800 - -int test_size = 32; -struct gm_port *netPort = 0; -volatile void *netInBuffer = 0; -volatile void *netDmaInBuffer = 0; -volatile void *netDmaOutBuffer = 0; -static void *netOutBuffer = 0; -gm_status_t status; -gm_u32_t receiver_node_id; -gm_s_e_id_message_t *id_message = 0; -unsigned int my_global_id = 0; -gm_u32_t my_node_id; -gm_u32_t receiver_global_id; -gm_remote_ptr_t directed_send_addr; - -void -cleanup() { - if (netPort) { - if (netDmaInBuffer) { - gm_dma_free (netPort, netDmaInBuffer); - } - if (netDmaOutBuffer) { - gm_dma_free (netPort, netDmaOutBuffer); - } - if (netInBuffer) { - gm_dma_free (netPort, netInBuffer); - } - if (netOutBuffer) { - gm_dma_free (netPort, netOutBuffer); - } - if (id_message) { - gm_dma_free (netPort, id_message); - } - gm_close (netPort); - gm_finalize(); - } - //gm_exit (status); -} - - -typedef struct -{ - int messages_expected; - int callbacks_pending; -} gm_s_e_context_t; - -gm_s_e_context_t context; -int send_complete = 0; - -/* This function is called inside gm_unknown() when there is a callback - ready to be processed. It tells us that a send has completed, either - successfully or with error. */ -static void -my_send_callback (struct gm_port *port, void *the_context, - gm_status_t the_status) -{ - /* One pending callback has been received */ - ((gm_s_e_context_t *)the_context)->callbacks_pending--; - - switch (the_status) - { - case GM_SUCCESS: - send_complete = 1; - printf ("**** Send complete!\n"); - break; - - case GM_SEND_DROPPED: - printf ("**** Send dropped!\n"); - break; - - default: - gm_perror ("Send completed with error", the_status); - } -} - -/* Transmit init message to slave */ -void -send_init_message(gm_u32_t nid) { - unsigned long send_length; - daqMessage *daqSendMessage; - daqSendMessage = (daqMessage *)netOutBuffer; - sprintf (daqSendMessage->message, "STT"); - send_length = (unsigned long) sizeof(*daqSendMessage); - send_complete = 0; - gm_send_with_callback (netPort, - netOutBuffer, - GM_RCV_MESSAGE_SIZE, - send_length, - GM_DAQ_PRIORITY, - nid, - 2, - my_send_callback, - &context); - context.callbacks_pending++; - for(;send_complete;); -} - - -gm_u32_t -recv_init_message() { - int i; - gm_recv_event_t *event; - daqMessage *rcvData; - gm_u32_t node_id = 0; - gm_s_e_id_message_t *id_message; - -for ( i = 0; i < 100; i++) { - /* Slave receives init message from master */ - event = gm_blocking_receive (netPort); - switch (GM_RECV_EVENT_TYPE(event)) { - case GM_RECV_EVENT: - case GM_HIGH_RECV_EVENT: - case GM_PEER_RECV_EVENT: - case GM_FAST_PEER_RECV_EVENT: - rcvData = (daqMessage *)gm_ntohp(event->recv.buffer); - if (rcvData == 0) { - printf("received zero pointer\n"); - break; - } - - if (gm_ntoh_u32 (event->recv.length) - == sizeof (gm_s_e_id_message_t)) { - id_message = gm_ntohp (event->recv.message); - receiver_global_id = gm_ntoh_u32(id_message->global_id); - directed_send_addr = - gm_ntoh_u64(id_message->directed_recv_buffer_addr); - printf("received remote buffer pointer\n"); - } else - - // Received startup message - // All clients must send this message on startup - if (strcmp(rcvData->message,"STT") == 0) { - node_id = gm_ntoh_u16(event->recv.sender_node_id); - printf("Recv'd init from node %d\n", node_id); - gm_send_with_callback (netPort, - id_message, - GM_RCV_MESSAGE_SIZE, - sizeof(*id_message), - GM_DAQ_PRIORITY, - node_id, - 2, - my_send_callback, - &context); - context.callbacks_pending++; - } else { - printf("invalid message received\n"); - } - gm_provide_receive_buffer (netPort, netInBuffer, GM_RCV_MESSAGE_SIZE, - GM_DAQ_PRIORITY); - return node_id; - break; - case GM_NO_RECV_EVENT: - break; - - default: - gm_unknown (netPort, event); - break; - } -} -return 0; -} - -inline void wait_for_test_data() { - for (;((int *)netInBuffer) [test_size-1] == 0;); -} - -inline void -send_test_data(gm_u32_t nid) { - int i; - for (i = 0 ; i < test_size; i++) - ((int *)netDmaOutBuffer)[i] = 1; - - send_complete = 0; - gm_directed_send_with_callback (netPort, - netDmaOutBuffer, - (gm_remote_ptr_t)directed_send_addr, - (unsigned long) sizeof(int) * test_size, - GM_DAQ_PRIORITY, - nid, - 2, - my_send_callback, - &context); - context.callbacks_pending++; - for(;send_complete;); -} - -int -main(int argc, char *argv[]) -{ - int i; - pthread_attr_t attr; - rtl_pthread_t wthread; - void *fe_start(void *); - - if (argc != 2) { - printf ("Usage: %s --slave | %s <receive node name>\n", - argv[0], argv[0]); - return 1; - } - if (!strcmp(argv[1], "--slave")) slave = 1; - else strcpy(receiver_nodename, argv[1]); - - // Initialize interface - gm_init(); - - status = gm_open (&netPort, 0 /* board */, 2 /*port */, "blah", - (enum gm_api_version) GM_API_VERSION_1_1); - if (status != GM_SUCCESS) { - gm_perror ("Couldn't open GM port", status); - cleanup(); - return 1; - } - - netDmaInBuffer = gm_dma_calloc (netPort, GM_RCV_BUFFER_COUNT, - GM_RCV_BUFFER_LENGTH); - if (netDmaInBuffer == 0) { - printf ("Couldn't allocate netDmaInBuffer\n"); - cleanup(); - return 1; - } - - netDmaOutBuffer = gm_dma_calloc (netPort, GM_RCV_BUFFER_COUNT, - GM_RCV_BUFFER_LENGTH); - if (netDmaOutBuffer == 0) { - printf ("Couldn't allocate netDmaOutBuffer\n"); - cleanup(); - return 1; - } - - netInBuffer = gm_dma_calloc (netPort, GM_RCV_BUFFER_COUNT, - GM_RCV_BUFFER_LENGTH); - if (netInBuffer == 0) { - printf ("Couldn't allocate netInBuffer\n"); - cleanup(); - return 1; - } - gm_provide_receive_buffer (netPort, netInBuffer, GM_RCV_MESSAGE_SIZE, - GM_DAQ_PRIORITY); - - netOutBuffer = gm_dma_calloc (netPort, GM_RCV_BUFFER_COUNT, - GM_RCV_BUFFER_LENGTH); - if (netOutBuffer == 0) { - printf("Couldn't allocate out_buffer\n"); - cleanup(); - return 1; - } - - id_message = (gm_s_e_id_message_t *)gm_dma_calloc (netPort, 1, - sizeof(*id_message)); - if (id_message == 0) { - printf ("Couldn't allocate output buffer for id_message\n"); - cleanup(); - return 1; - } - - gm_get_node_id (netPort, &my_node_id); - status = gm_node_id_to_global_id (netPort, my_node_id, &my_global_id); - if (status != GM_SUCCESS) { - gm_perror ("Couldn't convert node ID to global ID", status); - cleanup(); - return 1; - } - - id_message->directed_recv_buffer_addr = - gm_hton_u64((gm_size_t)netDmaInBuffer); - id_message->global_id = gm_hton_u32(my_global_id); - - gm_allow_remote_memory_access (netPort); - -#if 0 - rtl_pthread_attr_init(&attr); - rtl_pthread_attr_setcpu_np(&attr, 1); - /* mark this CPU as reserved - only RTLinux runs on it */ rtl_pthread_attr_setreserve_np(&attr, 1); - rtl_pthread_create(&wthread, &attr, fe_start, 0); -#endif - fe_start(0); - - //rtl_main_wait(); -} - -void* -fe_start(void *args) { - int i; - if (!slave) { - unsigned long cpuClock[2]; - status = gm_host_name_to_node_id_ex (netPort, 10000000, - receiver_nodename, - &receiver_node_id); - if (status == GM_SUCCESS) - printf ("receiver node ID is %d\n", receiver_node_id); - else { - printf ("Conversion of nodename %s to node id failed\n", - receiver_nodename); - gm_perror ("", status); - cleanup(); - return 1; - } - rdtscl(cpuClock[0]); - send_init_message(receiver_node_id); - gm_u32_t node_id = recv_init_message(); - rdtscl(cpuClock[1]); - printf("roundtrip time is %d\n", (cpuClock[1] - cpuClock[0])/CPU_RATE); - for (i = 0; i < test_size; i++) - ((int *)netDmaInBuffer) [i] = 0; - - recv_init_message(); /* receive remote buffer pointer */ - //send_test_data(node_id); - //wait_for_test_data(); - usleep(1000000); - printf("data %d\n", *((volatile int *)netDmaInBuffer)); - } else { - gm_u32_t node_id = recv_init_message(); - send_init_message(node_id); - recv_init_message(); /* receive remote buffer pointer */ -// for (i = 0; i < test_size; i++) -// ((int *)netDmaInBuffer) [i] = 0; - //wait_for_test_data(); - send_test_data(node_id); - } - cleanup(); - return -1; -} diff --git a/src/fe/test/gm_simple_example.h b/src/fe/test/gm_simple_example.h deleted file mode 100644 index 2905d8c88..000000000 --- a/src/fe/test/gm_simple_example.h +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************-*-c-*- - * Myricom GM networking software and documentation * - * Copyright (c) 1999-2003 by Myricom, Inc. * - * All rights reserved. See the file `COPYING' for copyright notice. * - *************************************************************************/ - -/** - @file gm_simple_example.h - - Include file for gm_simple_example_send.c and gm_simple_example_recv.c. -*/ - -#include "gm.h" - -/* The following define allows the programmer to turn GM strong typeing off - * regardless of the setting in gm.h. Note that if this effectively changes - * the definition in gm.h, the compiler will probably issue a warning, which - * may safely be ignored. - * - * It is *not* recommended to override GM_STRONG_TYPES to 1; see the definition - * in gm.h for the reasons. - */ -#if 0 -#define GM_STRONG_TYPES 0 -#endif - -#define GM_SIMPLE_EXAMPLE_PORT_NUM_RECV 4 -#define GM_SIMPLE_EXAMPLE_PORT_NUM_SEND 2 - -#define GM_SIMPLE_EXAMPLE_PRIORITY GM_LOW_PRIORITY - -#define GM_SIMPLE_EXAMPLE_SIZE 7 -#define GM_SIMPLE_EXAMPLE_BUFFER_COUNT 1 -#define GM_SIMPLE_EXAMPLE_BUFFER_LENGTH \ - (gm_max_length_for_size(GM_SIMPLE_EXAMPLE_SIZE)) - - -typedef struct /* Receiver-to-sender ID message */ -{ - gm_u64_n_t directed_recv_buffer_addr; /* UVA of directed-receive buffer */ - gm_u32_n_t global_id; /* Receiver's GM global ID */ - gm_u32_n_t slack; /* Make length a multiple of 64 */ -} gm_s_e_id_message_t; diff --git a/src/fe/test/gm_simple_example_recv.c b/src/fe/test/gm_simple_example_recv.c deleted file mode 100644 index 069076c3e..000000000 --- a/src/fe/test/gm_simple_example_recv.c +++ /dev/null @@ -1,317 +0,0 @@ -/************************************************************************* - * Myricom GM networking software and documentation * - * Copyright (c) 2001-2003 by Myricom, Inc. * - * All rights reserved. See the file `COPYING' for copyright notice. * - * * - * Portions Copyright 1999 by Cam Macdonnell - University of Alberta. * - * Used with permission. * - *************************************************************************/ - -/** - @file gm_simple_example_recv.c - - * Simple Send/Recv for GM - * Author: Max Stern (Myricom) - * Based on a program by Cam Macdonell - University of Alberta - * - * Syntax: gm_simple_example_recv <sender_nodename> [<local_board_num>] - * - * <sender_nodename> is required. Include the board_num suffix if the - * sender is using a board_num other than 0; e.g., hosta:1 for board 1 - * on host "hosta". - * - * The default for <local_board_num> is 0. - * - * Description: - * - * This program, together with gm_simple_example_send, serves as a super- - * simple example of sending and receiving in GM, using both the basic send - * (gm_send type) and the directed send (gm_directed_send type) paradigms. - * - * The programs are written to be portable and interoperable without - * respect to the pointer size or the "endianness" of the host platforms. - * - * This program, the "receiver" or slave process, takes the following main - * actions (see commentary in the code below for the "how" details): - * - * - uses gm_send_with_callback() to transmit its global id and its - * directed-receive buffer address to the "sender" process (which may be - * on the same or a different host); - * - * - loops on gm_receive() until both the send callback from the above send - * and an incoming message from gm_simple_example_send have been received - * (the incoming message serves as notification that the directed-receive - * buffer has been modified); - * - * - displays the contents of its directed-receive buffer, showing the - * contents stored there by gm_simple_example_send; - * - * - exits. - * - * See also the Description and the Usage Note in gm_simple_example_send.c. - * - * */ - -#include <stdlib.h> -#include <stdio.h> -#include "gm.h" -#include "gm_simple_example.h" - -/** A structure used to store the state of this simple example program. */ - -typedef struct -{ - int messages_expected; - int callbacks_pending; -} gm_s_e_context_t; - -static void wait_for_events (struct gm_port *p, - gm_s_e_context_t *the_context); -static void my_send_callback (struct gm_port *port, - void *the_context, - gm_status_t the_status); - - -int -main (int argc, char **argv) -{ - struct gm_port *my_port; - char sender_nodename[64]; - gm_s_e_context_t context; - gm_status_t main_status; - int my_board_num = 0; /* Default board_num is 0 */ - gm_u32_t my_node_id, sender_node_id; - unsigned int my_global_id = 0; - void *directed_receive_buffer; - void *in_buffer; - gm_s_e_id_message_t *id_message; - gm_size_t alloc_length; - - context.messages_expected = 0; - context.callbacks_pending = 0; - - gm_init(); - - /* Parse the program argument(s) */ - - if ((argc < 2) || (argc > 3)) - { - printf ("USAGE: gm_simple_example_recv <sender_nodename> " - "[<local_board_num>]\n"); - main_status = GM_INVALID_PARAMETER; - goto abort_with_nothing; - } - if (gm_strlen (argv[1]) + 1 > sizeof (sender_nodename)) - { - printf ("[recv] *** ERROR: " - "sender nodename length %ld exceeds maximum of %ld\n", - gm_strlen (argv[1]), sizeof (sender_nodename) - 1); - main_status = GM_INVALID_PARAMETER; - goto abort_with_nothing; - } - gm_strncpy (sender_nodename, /* Mandatory 1st parameter */ - argv[1], - sizeof (sender_nodename) - 1); - if (argc > 2) - { - my_board_num = atoi (argv[2]); /* Optional 2nd parameter */ - } - - /* Open a port on our local interface. */ - - main_status = gm_open (&my_port, my_board_num, - GM_SIMPLE_EXAMPLE_PORT_NUM_RECV, - "gm_simple_example_recv", - (enum gm_api_version) GM_API_VERSION_1_1); - if (main_status == GM_SUCCESS) - { - printf ("[recv] Opened board %d port %d\n", - my_board_num, GM_SIMPLE_EXAMPLE_PORT_NUM_RECV); - } - else - { - gm_perror ("[recv] Couldn't open GM port", main_status); - goto abort_with_nothing; - } - - gm_get_node_id (my_port, &my_node_id); - main_status = gm_node_id_to_global_id (my_port, my_node_id, &my_global_id); - if (main_status != GM_SUCCESS) - { - gm_perror ("[recv] Couldn't convert node ID to global ID", main_status); - goto abort_with_open_port; - } - - /* Try to convert the sender's hostname into a node ID. */ - - main_status = gm_host_name_to_node_id_ex - (my_port, 10000000, sender_nodename, &sender_node_id); - if (main_status == GM_SUCCESS) - { - printf ("[recv] sender node ID is %d\n", sender_node_id); - } - else - { - printf ("[recv] Conversion of nodename %s to node id failed\n", - sender_nodename); - gm_perror ("[recv]", main_status); - goto abort_with_open_port; - } - if (my_node_id == sender_node_id) - { - printf ("[recv] NOTE: sender and receiver are same node, id=%d\n", - my_node_id); - } - - /* Allocate DMAable message buffers. */ - - alloc_length = sizeof(*id_message); - id_message = (gm_s_e_id_message_t *)gm_dma_calloc (my_port, 1, alloc_length); - if (id_message == 0) - { - printf ("[recv] Couldn't allocate output buffer for id_message\n"); - main_status = GM_OUT_OF_MEMORY; - goto abort_with_open_port; - } - - in_buffer = gm_dma_calloc (my_port, GM_SIMPLE_EXAMPLE_BUFFER_COUNT, - GM_SIMPLE_EXAMPLE_BUFFER_LENGTH); - if (in_buffer == 0) - { - printf ("[recv] Couldn't allocate in_buffer\n"); - main_status = GM_OUT_OF_MEMORY; - goto abort_with_id_message; - } - - directed_receive_buffer = gm_dma_calloc (my_port, - GM_SIMPLE_EXAMPLE_BUFFER_COUNT, - GM_SIMPLE_EXAMPLE_BUFFER_LENGTH); - if (directed_receive_buffer == 0) - { - printf ("[recv] Couldn't allocate directed_receive_buffer\n"); - main_status = GM_OUT_OF_MEMORY; - goto abort_with_in_buffer; - } - - /* Allow any GM process to modify any of the local DMAable buffers. */ - - gm_allow_remote_memory_access (my_port); - - /* Compose and send the message to tell sender our node_id and our - directed-receive-buffer address */ - - /* Here we take advantage of the fact that gm_remote_ptr_t is 64 bits for - all platforms and architectures. */ - id_message->directed_recv_buffer_addr = - gm_hton_u64((gm_size_t)directed_receive_buffer); - id_message->global_id = gm_hton_u32(my_global_id); - - /* If, through a programming error, we had defined things such that - sizeof(*id_message) > gm_max_length_for_size(GM_SIMPLE_EXAMPLE_SIZE), - the following GM API call would return an error at run time. */ - gm_send_with_callback (my_port, - id_message, - GM_SIMPLE_EXAMPLE_SIZE, - sizeof(*id_message), - GM_SIMPLE_EXAMPLE_PRIORITY, - sender_node_id, - GM_SIMPLE_EXAMPLE_PORT_NUM_SEND, - my_send_callback, - &context); - context.callbacks_pending++; - - gm_provide_receive_buffer (my_port, in_buffer, GM_SIMPLE_EXAMPLE_SIZE, - GM_SIMPLE_EXAMPLE_PRIORITY); - - /* Prefill the directed-receive buffer with error message; - we should see it change. If not, an error has occurred. */ - sprintf ((char *)directed_receive_buffer, "*** AN ERROR HAS OCCURRED!"); - - context.messages_expected = 1; /* Now, we do expect a message from sender */ - - /* Nothing more to do but wait for callbacks and the incoming messages */ - - wait_for_events (my_port, &context); - - printf ("[recv] " - "Having received the incoming message from the sender, the\n" - " directed-receive buffer contains \"%s\"\n", - directed_receive_buffer); - - printf ("[recv] gm_simple_example_recv completed successfully\n"); - - gm_dma_free (my_port, directed_receive_buffer); - main_status = GM_SUCCESS; - - abort_with_in_buffer: - gm_dma_free (my_port, in_buffer); - abort_with_id_message: - gm_dma_free (my_port, id_message); - abort_with_open_port: - gm_close (my_port); - abort_with_nothing: - gm_finalize(); - gm_exit (main_status); -} - -static void -wait_for_events (struct gm_port *my_port, gm_s_e_context_t *the_context) -{ - gm_recv_event_t *event; - void *buffer; - unsigned int size; - - - while ((the_context->callbacks_pending > 0) - || (the_context->messages_expected > 0)) - { - event = gm_receive (my_port); - - switch (GM_RECV_EVENT_TYPE(event)) - { - case GM_RECV_EVENT: - case GM_PEER_RECV_EVENT: - case GM_FAST_PEER_RECV_EVENT: - printf ("[recv] Received incoming message: \"%s\"\n", - (char *) gm_ntohp (event->recv.message)); - the_context->messages_expected--; - /* Return the buffer for reuse */ - buffer = gm_ntohp (event->recv.buffer); - size = (unsigned int)gm_ntoh_u8 (event->recv.size); - gm_provide_receive_buffer (my_port, buffer, size, - GM_SIMPLE_EXAMPLE_PRIORITY); - break; - - case GM_NO_RECV_EVENT: - break; - - default: - gm_unknown (my_port, event); /* gm_unknown calls the callback */ - } - } -} - -/* This function is called inside gm_unknown() when there is a callback - ready to be processed. It tells us that a send has completed, either - successfully or with error. */ - -static void -my_send_callback (struct gm_port *port, void *the_context, - gm_status_t the_status) -{ - /* One pending callback has been received */ - ((gm_s_e_context_t *)the_context)->callbacks_pending--; - - switch (the_status) - { - case GM_SUCCESS: - break; - - case GM_SEND_DROPPED: - printf ("**** Send dropped!\n"); - break; - - default: - gm_perror ("Send completed with error", the_status); - } -} diff --git a/src/fe/test/gm_simple_example_send.c b/src/fe/test/gm_simple_example_send.c deleted file mode 100644 index 97fbbd482..000000000 --- a/src/fe/test/gm_simple_example_send.c +++ /dev/null @@ -1,320 +0,0 @@ -/************************************************************************* - * Myricom GM networking software and documentation * - * Copyright (c) 2001-2003 by Myricom, Inc. * - * All rights reserved. See the file `COPYING' for copyright notice. * - * * - * Portions Copyright 1999 by Cam Macdonnell - University of Alberta. * - * Used with permission. * - *************************************************************************/ - -/** - @file gm_simple_example_send.c - - * Simple Send/Recv for GM - * Author: Max Stern (Myricom) - * Based on a program by Cam Macdonell - University of Alberta - * - * Syntax: gm_simple_example_send [<local_board_num>] - * - * The default for <local_board_num> is 0. - * - * Description: - * - * This program, together with gm_simple_example_recv, serves as a super- - * simple example of sending and receiving in GM, using both the basic send - * (gm_send type) and the directed send (gm_directed_send type) paradigms. - * - * The programs are written to be portable and interoperable without - * respect to the pointer size or the "endianness" of the host platforms. - * - * This program, the "sender" or master process, takes the following main - * actions (see commentary in the code below for the "how" details): - * - * - loops on gm_receive() until it receives a message. It assumes that - * this message (if the proper length) contains the receiver's global id - * and the receiver's directed-send buffer address; - * - * - uses gm_directed_send_with_callback() to copy a message directly into - * the receiver's memory (note: the receiver does not do a gm_receive()); - * - * - uses gm_send_with_callback() to transmit a normal message, which - * the receiver will get via gm_receive(); - * - * - loops on gm_receive() until both the send callbacks have been consumed; - * - * - exits. - * - * Usage Note: - * - * Assume the sender is to run on board 1 on hosta, and the receiver - * on board 0 on hostb. The commands would look like this: - * - * First, on hostb: - * hostb> gm_simple_example_recv hosta:1 - * - * Then, on hosta: - * hosta> gm_simple_example_send 1 - * - * Note: The sender and the receiver use different GM ports. This makes it - * possible, if desired, to run the sender and receiver over the same - * interface. The commands might look like this: - * - * First, on hosta: - * hosta> gm_simple_example_recv hosta & - * - * Then, also on hosta: - * hosta> gm_simple_example_send - * - * See also the Description in gm_simple_example_recv.c. - * - * */ - -#include <stdlib.h> -#include <stdio.h> -#include "gm.h" -#include "gm_simple_example.h" - -static void my_send_callback (struct gm_port *port, - void *the_context, - gm_status_t the_status); - - -int -main (int argc, char **argv) -{ - static struct gm_port *my_port = 0; - static void *out_buffer = 0, *in_buffer = 0, *directed_send_buffer = 0; - int my_board_num = 0; /* Default board_num is 0 */ - gm_u32_t receiver_node_id; - gm_u32_t receiver_global_id; - unsigned int send_length; - int expected_messages = 1; - gm_remote_ptr_t directed_send_addr; - gm_recv_event_t *event; - gm_status_t main_status; -/* expected_callbacks makes sure we don't exit until we have handled all - the callbacks we expect. */ - static int expected_callbacks = 0; - - gm_init(); - - /* Parse the program argument(s) */ - - if (argc > 2) - { - printf ("USAGE: gm_simple_example_send [<local_board_num>]\n"); - main_status = GM_INVALID_PARAMETER; - goto abort_with_nothing; - } - if (argc > 1) - { - my_board_num = atoi (argv[1]); /* Optional parameter */ - } - - /* Open a port on our local interface. */ - - main_status = gm_open (&my_port, my_board_num, - GM_SIMPLE_EXAMPLE_PORT_NUM_SEND, - "gm_simple_example_send", - (enum gm_api_version) GM_API_VERSION_1_1); - if (main_status == GM_SUCCESS) - { - printf ("[send] Opened board %d port %d\n", - my_board_num, GM_SIMPLE_EXAMPLE_PORT_NUM_SEND); - } - else - { - gm_perror ("[send] Couldn't open GM port", main_status); - goto abort_with_nothing; - } - - /* Allocate DMAable message buffers. */ - - out_buffer = gm_dma_calloc (my_port, GM_SIMPLE_EXAMPLE_BUFFER_COUNT, - GM_SIMPLE_EXAMPLE_BUFFER_LENGTH); - if (out_buffer == 0) - { - printf ("[send] Couldn't allocate out_buffer\n"); - main_status = GM_OUT_OF_MEMORY; - goto abort_with_open_port; - } - - in_buffer = gm_dma_calloc (my_port, GM_SIMPLE_EXAMPLE_BUFFER_COUNT, - GM_SIMPLE_EXAMPLE_BUFFER_LENGTH); - if (in_buffer == 0) - { - printf ("[send] Couldn't allocate in_buffer\n"); - main_status = GM_OUT_OF_MEMORY; - goto abort_with_out_buffer; - } - - directed_send_buffer = gm_dma_calloc (my_port, - GM_SIMPLE_EXAMPLE_BUFFER_COUNT, - GM_SIMPLE_EXAMPLE_BUFFER_LENGTH); - if (directed_send_buffer == 0) - { - printf ("[send] Couldn't allocate directed_send_buffer\n"); - main_status = GM_OUT_OF_MEMORY; - goto abort_with_in_buffer; - } - - /* Note that all send tokens are available */ - - /* Tell GM where our receive buffer is */ - - gm_provide_receive_buffer (my_port, in_buffer, GM_SIMPLE_EXAMPLE_SIZE, - GM_SIMPLE_EXAMPLE_PRIORITY); - - /* Wait for the message from gm_simple_example_recv */ - - while (expected_messages) - { - void *recv_buffer; - unsigned int size; - gm_s_e_id_message_t *id_message; - gm_u32_t recv_length; - - event = gm_receive (my_port); - recv_length = gm_ntoh_u32 (event->recv.length); - - switch (GM_RECV_EVENT_TYPE(event)) - { - case GM_RECV_EVENT: - case GM_PEER_RECV_EVENT: - case GM_FAST_PEER_RECV_EVENT: - if (recv_length != sizeof (gm_s_e_id_message_t)) - { - printf ("[send] *** ERROR: incoming message length %d " - "incorrect; should be %ld\n", - recv_length, sizeof (gm_s_e_id_message_t)); - main_status = GM_FAILURE; /* Unexpected incoming message */ - goto abort_with_directed_send_buffer; - } - - id_message = gm_ntohp (event->recv.message); - receiver_global_id = gm_ntoh_u32(id_message->global_id); - directed_send_addr = - gm_ntoh_u64(id_message->directed_recv_buffer_addr); - main_status = gm_global_id_to_node_id(my_port, - receiver_global_id, - &receiver_node_id); - if (main_status != GM_SUCCESS) - { - gm_perror ("[send] Couldn't convert global ID to node ID", - main_status); - goto abort_with_directed_send_buffer; - } - - expected_messages--; - - /* Return the buffer for reuse */ - - recv_buffer = gm_ntohp (event->recv.buffer); - size = (unsigned int)gm_ntoh_u8 (event->recv.size); - gm_provide_receive_buffer (my_port, recv_buffer, size, - GM_SIMPLE_EXAMPLE_PRIORITY); - break; - - case GM_NO_RECV_EVENT: - break; - - default: - gm_unknown (my_port, event); /* gm_unknown calls the callback */ - } - } /* while */ - - sprintf (directed_send_buffer, "Directed send was successful!"); - - /* Copy the buffer directly into the receiver's memory */ - - gm_directed_send_with_callback (my_port, - directed_send_buffer, - (gm_remote_ptr_t) directed_send_addr, - (unsigned long) - gm_strlen (directed_send_buffer) + 1, - GM_SIMPLE_EXAMPLE_PRIORITY, - receiver_node_id, - GM_SIMPLE_EXAMPLE_PORT_NUM_RECV, - my_send_callback, - &expected_callbacks); - expected_callbacks++; - - sprintf (out_buffer, "This is the sender!!"); - - /* Now send a regular message, which will signal the receiver to look at - its directed-send buffer */ - - send_length = (unsigned long) gm_strlen (out_buffer) + 1; - gm_send_with_callback (my_port, - out_buffer, - GM_SIMPLE_EXAMPLE_SIZE, - send_length, - GM_SIMPLE_EXAMPLE_PRIORITY, - receiver_node_id, - GM_SIMPLE_EXAMPLE_PORT_NUM_RECV, - my_send_callback, - &expected_callbacks); - expected_callbacks++; - - /* Now we wait for the callbacks for the sends we did above */ - while (expected_callbacks) - { - event = gm_receive (my_port); - - switch (GM_RECV_EVENT_TYPE(event)) - { - case GM_RECV_EVENT: - case GM_PEER_RECV_EVENT: - case GM_FAST_PEER_RECV_EVENT: - printf ("[send] Receive Event (UNEXPECTED)\n"); - main_status = GM_FAILURE; /* Unexpected incoming message */ - goto abort_with_directed_send_buffer; - - case GM_NO_RECV_EVENT: - break; - - default: - gm_unknown (my_port, event); /* gm_unknown calls the callback */ - } - } - - printf ("[send] gm_simple_example_send completed successfully\n"); - main_status = GM_SUCCESS; - - abort_with_directed_send_buffer: - gm_dma_free (my_port, directed_send_buffer); - abort_with_in_buffer: - gm_dma_free (my_port, in_buffer); - abort_with_out_buffer: - gm_dma_free (my_port, out_buffer); - abort_with_open_port: - gm_close (my_port); - abort_with_nothing: - gm_finalize(); - gm_exit (main_status); -} - -/* This function is called inside gm_unknown() when there is a callback - ready to be processed. It tells us that a send has completed, either - successfully or with error. */ - -static void -my_send_callback (struct gm_port *port, void *the_context, - gm_status_t the_status) -{ - /* One pending callback has been received */ - (*(int *)the_context)--; - - switch (the_status) - { - case GM_SUCCESS: - break; - - case GM_SEND_DROPPED: - printf ("**** Send dropped!\n"); - break; - - default: - gm_perror ("Send completed with error", the_status); - } -} -- GitLab