• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ramster.h
3  *
4  * Peer-to-peer transcendent memory
5  *
6  * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp.
7  */
8 
9 #ifndef _RAMSTER_H_
10 #define _RAMSTER_H_
11 
12 /*
13  * format of remote pampd:
14  *   bit 0 == intransit
15  *   bit 1 == is_remote... if this bit is set, then
16  *   bit 2-9 == remotenode
17  *   bit 10-22 == size
18  *   bit 23-30 == cksum
19  */
20 #define FAKE_PAMPD_INTRANSIT_BITS	1
21 #define FAKE_PAMPD_ISREMOTE_BITS	1
22 #define FAKE_PAMPD_REMOTENODE_BITS	8
23 #define FAKE_PAMPD_REMOTESIZE_BITS	13
24 #define FAKE_PAMPD_CHECKSUM_BITS	8
25 
26 #define FAKE_PAMPD_INTRANSIT_SHIFT	0
27 #define FAKE_PAMPD_ISREMOTE_SHIFT	(FAKE_PAMPD_INTRANSIT_SHIFT + \
28 					 FAKE_PAMPD_INTRANSIT_BITS)
29 #define FAKE_PAMPD_REMOTENODE_SHIFT	(FAKE_PAMPD_ISREMOTE_SHIFT + \
30 					 FAKE_PAMPD_ISREMOTE_BITS)
31 #define FAKE_PAMPD_REMOTESIZE_SHIFT	(FAKE_PAMPD_REMOTENODE_SHIFT + \
32 					 FAKE_PAMPD_REMOTENODE_BITS)
33 #define FAKE_PAMPD_CHECKSUM_SHIFT	(FAKE_PAMPD_REMOTESIZE_SHIFT + \
34 					 FAKE_PAMPD_REMOTESIZE_BITS)
35 
36 #define FAKE_PAMPD_MASK(x)		((1UL << (x)) - 1)
37 
pampd_make_remote(int remotenode,size_t size,unsigned char cksum)38 static inline void *pampd_make_remote(int remotenode, size_t size,
39 					unsigned char cksum)
40 {
41 	unsigned long fake_pampd = 0;
42 	fake_pampd |= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT;
43 	fake_pampd |= ((unsigned long)remotenode &
44 			FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS)) <<
45 				FAKE_PAMPD_REMOTENODE_SHIFT;
46 	fake_pampd |= ((unsigned long)size &
47 			FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS)) <<
48 				FAKE_PAMPD_REMOTESIZE_SHIFT;
49 	fake_pampd |= ((unsigned long)cksum &
50 			FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS)) <<
51 				FAKE_PAMPD_CHECKSUM_SHIFT;
52 	return (void *)fake_pampd;
53 }
54 
pampd_remote_node(void * pampd)55 static inline unsigned int pampd_remote_node(void *pampd)
56 {
57 	unsigned long fake_pampd = (unsigned long)pampd;
58 	return (fake_pampd >> FAKE_PAMPD_REMOTENODE_SHIFT) &
59 		FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS);
60 }
61 
pampd_remote_size(void * pampd)62 static inline unsigned int pampd_remote_size(void *pampd)
63 {
64 	unsigned long fake_pampd = (unsigned long)pampd;
65 	return (fake_pampd >> FAKE_PAMPD_REMOTESIZE_SHIFT) &
66 		FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS);
67 }
68 
pampd_remote_cksum(void * pampd)69 static inline unsigned char pampd_remote_cksum(void *pampd)
70 {
71 	unsigned long fake_pampd = (unsigned long)pampd;
72 	return (fake_pampd >> FAKE_PAMPD_CHECKSUM_SHIFT) &
73 		FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS);
74 }
75 
pampd_is_remote(void * pampd)76 static inline bool pampd_is_remote(void *pampd)
77 {
78 	unsigned long fake_pampd = (unsigned long)pampd;
79 	return (fake_pampd >> FAKE_PAMPD_ISREMOTE_SHIFT) &
80 		FAKE_PAMPD_MASK(FAKE_PAMPD_ISREMOTE_BITS);
81 }
82 
pampd_is_intransit(void * pampd)83 static inline bool pampd_is_intransit(void *pampd)
84 {
85 	unsigned long fake_pampd = (unsigned long)pampd;
86 	return (fake_pampd >> FAKE_PAMPD_INTRANSIT_SHIFT) &
87 		FAKE_PAMPD_MASK(FAKE_PAMPD_INTRANSIT_BITS);
88 }
89 
90 /* note that it is a BUG for intransit to be set without isremote also set */
pampd_mark_intransit(void * pampd)91 static inline void *pampd_mark_intransit(void *pampd)
92 {
93 	unsigned long fake_pampd = (unsigned long)pampd;
94 
95 	fake_pampd |= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT;
96 	fake_pampd |= 1UL << FAKE_PAMPD_INTRANSIT_SHIFT;
97 	return (void *)fake_pampd;
98 }
99 
pampd_mask_intransit_and_remote(void * marked_pampd)100 static inline void *pampd_mask_intransit_and_remote(void *marked_pampd)
101 {
102 	unsigned long pampd = (unsigned long)marked_pampd;
103 
104 	pampd &= ~(1UL << FAKE_PAMPD_INTRANSIT_SHIFT);
105 	pampd &= ~(1UL << FAKE_PAMPD_ISREMOTE_SHIFT);
106 	return (void *)pampd;
107 }
108 
109 extern int ramster_remote_async_get(struct tmem_xhandle *,
110 				bool, int, size_t, uint8_t, void *extra);
111 extern int ramster_remote_put(struct tmem_xhandle *, char *, size_t,
112 				bool, int *);
113 extern int ramster_remote_flush(struct tmem_xhandle *, int);
114 extern int ramster_remote_flush_object(struct tmem_xhandle *, int);
115 extern int r2net_register_handlers(void);
116 extern int r2net_remote_target_node_set(int);
117 
118 #endif /* _TMEM_H */
119