debuggers.hg

view tools/memshr/bidir-daemon.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
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 #include <pthread.h>
20 #include <inttypes.h>
21 #include <unistd.h>
23 #include "bidir-hash.h"
24 #include "memshr-priv.h"
26 static struct blockshr_hash *blks_hash;
28 void* bidir_daemon(void *unused)
29 {
30 uint32_t nr_ent, max_nr_ent, tab_size, max_load, min_load;
31 static uint64_t shrhnd = 1;
33 while(1)
34 {
35 blockshr_hash_sizes( blks_hash,
36 &nr_ent,
37 &max_nr_ent,
38 &tab_size,
39 &max_load,
40 &min_load);
41 /* Remove some hints as soon as we get to 90% capacity */
42 if(10 * nr_ent > 9 * max_nr_ent)
43 {
44 uint64_t next_remove = shrhnd;
45 int to_remove;
46 int ret;
48 to_remove = 0.1 * max_nr_ent;
49 while(to_remove > 0)
50 {
51 ret = blockshr_shrhnd_remove(blks_hash, next_remove, NULL);
52 if(ret < 0)
53 {
54 /* We failed to remove an entry, because of a serious hash
55 * table error */
56 DPRINTF("Could not remove handle %"PRId64", error: %d\n",
57 next_remove, ret);
58 /* Force to exit the loop early */
59 to_remove = 0;
60 } else
61 if(ret > 0)
62 {
63 /* Managed to remove the entry. Note next_remove not
64 * incremented, in case there are duplicates */
65 shrhnd = next_remove;
66 to_remove--;
67 } else
68 {
69 /* Failed to remove, because there is no such handle */
70 next_remove++;
71 }
72 }
73 }
75 sleep(1);
76 }
77 }
79 void bidir_daemon_launch(void)
80 {
81 pthread_t thread;
83 pthread_create(&thread, NULL, bidir_daemon, NULL);
84 }
86 void bidir_daemon_initialize(struct blockshr_hash *blks)
87 {
88 blks_hash = blks;
89 bidir_daemon_launch();
90 }