ia64/xen-unstable

view tools/blktap2/drivers/profile.h @ 19647:1c627434605e

blktap2: a completely rewritten blktap implementation

Benefits to blktap2 over the old version of blktap:

* Isolation from xenstore - Blktap devices are now created directly on
the linux dom0 command line, rather than being spawned in response
to XenStore events. This is handy for debugging, makes blktap
generally easier to work with, and is a step toward a generic
user-level block device implementation that is not Xen-specific.

* Improved tapdisk infrastructure: simpler request forwarding, new
request scheduler, request merging, more efficient use of AIO.

* Improved tapdisk error handling and memory management. No
allocations on the block data path, IO retry logic to protect
guests
transient block device failures. This has been tested and is known
to work on weird environments such as NFS soft mounts.

* Pause and snapshot of live virtual disks (see xmsnap script).

* VHD support. The VHD code in this release has been rigorously
tested, and represents a very mature implementation of the VHD
image
format.

* No more duplication of mechanism with blkback. The blktap kernel
module has changed dramatically from the original blktap. Blkback
is now always used to talk to Xen guests, blktap just presents a
Linux gendisk that blkback can export. This is done while
preserving the zero-copy data path from domU to physical device.

These patches deprecate the old blktap code, which can hopefully be
removed from the tree completely at some point in the future.

Signed-off-by: Jake Wires <jake.wires@citrix.com>
Signed-off-by: Dutch Meyer <dmeyer@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 11:52:31 2009 +0100 (2009-05-26)
parents
children
line source
1 /*
2 * Copyright (c) 2008, XenSource Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of XenSource Inc. nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
20 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
29 #ifndef __TAP_PROFILE_H__
30 #define __TAP_PROFILE_H__
32 #ifndef _GNU_SOURCE
33 #define _GNU_SOURCE
34 #endif
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <syslog.h>
41 #include <sys/time.h>
42 #include <time.h>
43 #include <fcntl.h>
44 #include <inttypes.h>
46 //#define PROFILING
47 //#define LOGGING
49 #define TAPPROF_IN 1
50 #define TAPPROF_OUT 2
52 struct profile_times {
53 char *fn_name;
54 uint64_t in, out_sum, cnt;
55 };
57 struct profile_info {
58 FILE *log;
59 int size;
60 char *name;
61 unsigned long long seq;
62 struct profile_times *pt;
63 };
65 #ifdef PROFILING
67 static inline void
68 tp_open(struct profile_info *prof, char *tap_name, char *log_name, int size)
69 {
70 memset(prof, 0, sizeof(struct profile_info));
71 #ifdef LOGGING
72 prof->log = fopen(log_name, "w");
73 #endif
74 prof->size = size;
75 prof->name = strdup(tap_name);
76 prof->pt = malloc(sizeof(struct profile_times) * prof->size);
77 if (prof->pt)
78 memset(prof->pt, 0, sizeof(struct profile_times) * prof->size);
79 }
81 static inline void
82 tp_close(struct profile_info *prof)
83 {
84 int i;
85 struct profile_times *pt;
87 for (i = 0; i < prof->size; i++) {
88 pt = &prof->pt[i];
89 if (pt->fn_name) {
90 syslog(LOG_DEBUG, "%s: %s: cnt: %llu, avg time: %llu\n",
91 prof->name, pt->fn_name, pt->cnt,
92 ((pt->cnt) ? (pt->out_sum / pt->cnt) : 0));
93 free(pt->fn_name);
94 }
95 }
97 #ifdef LOGGING
98 if (prof->log)
99 fclose(prof->log);
100 #endif
101 free(prof->name);
102 if (prof->pt)
103 free(prof->pt);
104 }
106 static inline u64
107 tp_get_id(struct profile_info *prof)
108 {
109 return prof->seq++;
110 }
112 static inline int
113 tp_fn_id(struct profile_info *prof, const char *name)
114 {
115 int i;
116 struct profile_times *pt;
118 for (i = 0; i < prof->size; i++) {
119 pt = &prof->pt[i];
120 if (!pt->fn_name)
121 return i;
122 if (!strcmp(pt->fn_name, name))
123 return i;
124 }
126 return prof->size - 1;
127 }
129 static inline void
130 __tp_in(struct profile_info *prof, const char *func)
131 {
132 long long _time;
133 int idx = tp_fn_id(prof, func);
134 struct profile_times *pt = &prof->pt[idx];
136 if (!pt->fn_name)
137 pt->fn_name = strdup(func);
139 asm volatile(".byte 0x0f, 0x31" : "=A" (_time));
140 pt->in = _time;
141 }
143 #define tp_in(prof) __tp_in(prof, __func__)
145 static inline void
146 __tp_out(struct profile_info *prof, const char *func)
147 {
148 long long _time;
149 int idx = tp_fn_id(prof, func);
150 struct profile_times *pt = &prof->pt[idx];
152 if (!pt->fn_name || !pt->in)
153 return;
155 asm volatile(".byte 0x0f, 0x31" : "=A" (_time));
156 pt->cnt++;
157 pt->out_sum += (_time - pt->in);
158 pt->in = 0;
159 }
161 #define tp_out(prof) __tp_out(prof, __func__)
163 static inline void
164 __tp_log(struct profile_info *prof, u64 id, const char *func, int direction)
165 {
166 long long _time;
167 asm volatile(".byte 0x0f, 0x31" : "=A" (_time));
169 if (direction == TAPPROF_IN)
170 __tp_in(prof, func);
171 else
172 __tp_out(prof, func);
174 #ifdef LOGGING
175 if (prof->log)
176 fprintf(prof->log, "%s: %s: %llu, %lld\n", func,
177 ((direction == TAPPROF_IN) ? "in" : "out"), id, _time);
178 #endif
179 }
181 #define tp_log(prof, id, direction) __tp_log(prof, id, __func__, direction)
183 #else
184 #define tp_open(prof, tname, lname, size) ((void)0)
185 #define tp_close(prof) ((void)0)
186 #define tp_in(prof) ((void)0)
187 #define tp_out(prof) ((void)0)
188 #define tp_log(prof, sec, direction) ((void)0)
189 #endif
191 #endif