debuggers.hg

view tools/memshr/bidir-hash.h @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 47ec2d131c22
children
line source
1 /******************************************************************************
2 *
3 * Copyright (c) 2009 Citrix Systems, Inc. (Grzegorz Milos)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __BIDIR_HASH_H__
20 #define __BIDIR_HASH_H__
22 #include <stdint.h>
23 #include "memshr-priv.h"
25 typedef struct vbdblk {
26 uint64_t sec;
27 uint16_t disk_id;
28 } vbdblk_t;
31 #if defined FINGERPRINT_MAP || BLOCK_MAP
32 #define DEFINE_SINGLE_MAP
33 #endif
35 /*******************************************************/
36 /* Fingerprint map */
37 /*******************************************************/
38 #if defined FINGERPRINT_MAP || !defined DEFINE_SINGLE_MAP
40 #undef BIDIR_NAME_PREFIX
41 #undef BIDIR_KEY
42 #undef BIDIR_VALUE
43 #undef BIDIR_KEY_T
44 #undef BIDIR_VALUE_T
45 static uint32_t fgprtshr_fgprt_hash(uint32_t h)
46 {
47 return h;
48 }
50 static uint32_t fgprtshr_mfn_hash(uint64_t m)
51 {
52 return (uint32_t)m;
53 }
55 static int fgprtshr_fgprt_cmp(uint32_t h1, uint32_t h2)
56 {
57 return (h1 == h2);
58 }
60 static int fgprtshr_mfn_cmp(uint32_t m1, uint32_t m2)
61 {
62 return (m1 == m2);
63 }
64 #define BIDIR_NAME_PREFIX fgprtshr
65 #define BIDIR_KEY fgprt
66 #define BIDIR_VALUE mfn
67 #define BIDIR_KEY_T uint32_t
68 #define BIDIR_VALUE_T xen_mfn_t
69 #include "bidir-namedefs.h"
71 #endif /* FINGERPRINT_MAP */
74 /*******************************************************/
75 /* Block<->Memory sharing handles */
76 /*******************************************************/
77 #if defined BLOCK_MAP || !defined DEFINE_SINGLE_MAP
79 #undef BIDIR_NAME_PREFIX
80 #undef BIDIR_KEY
81 #undef BIDIR_VALUE
82 #undef BIDIR_KEY_T
83 #undef BIDIR_VALUE_T
84 /* TODO better hashes! */
85 static inline uint32_t blockshr_block_hash(vbdblk_t block)
86 {
87 return (uint32_t)(block.sec) ^ (uint32_t)(block.disk_id);
88 }
90 static inline uint32_t blockshr_shrhnd_hash(uint64_t shrhnd)
91 {
92 return (uint32_t)shrhnd;
93 }
95 static inline int blockshr_block_cmp(vbdblk_t b1, vbdblk_t b2)
96 {
97 return (b1.sec == b2.sec) && (b1.disk_id == b2.disk_id);
98 }
100 static inline int blockshr_shrhnd_cmp(uint64_t h1, uint64_t h2)
101 {
102 return (h1 == h2);
103 }
104 #define BIDIR_NAME_PREFIX blockshr
105 #define BIDIR_KEY block
106 #define BIDIR_VALUE shrhnd
107 #define BIDIR_KEY_T vbdblk_t
108 #define BIDIR_VALUE_T uint64_t
109 #include "bidir-namedefs.h"
111 #endif /* BLOCK_MAP */
113 #endif /* __BIDIR_HASH_H__ */