~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/os/os0proc.c

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file os/os0proc.c
 
1
/******************************************************
21
2
The interface to the operating system
22
3
process control primitives
23
4
 
 
5
(c) 1995 Innobase Oy
 
6
 
24
7
Created 9/30/1995 Heikki Tuuri
25
8
*******************************************************/
26
9
 
31
14
 
32
15
#include "ut0mem.h"
33
16
#include "ut0byte.h"
34
 
#include <errno.h>
35
 
#include <unistd.h>
36
17
 
37
18
/* FreeBSD for example has only MAP_ANON, Linux has MAP_ANONYMOUS and
38
19
MAP_ANON but MAP_ANON is marked as deprecated */
46
27
/* Large page size. This may be a boot-time option on some platforms */
47
28
UNIV_INTERN ulint os_large_page_size;
48
29
 
49
 
/****************************************************************//**
 
30
/********************************************************************
50
31
Converts the current process id to a number. It is not guaranteed that the
51
32
number is unique. In Linux returns the 'process number' of the current
52
33
thread. That number is the same as one sees in 'top', for example. In Linux
53
 
the thread id is not the same as one sees in 'top'.
54
 
@return process id as a number */
 
34
the thread id is not the same as one sees in 'top'. */
55
35
UNIV_INTERN
56
36
ulint
57
37
os_proc_get_number(void)
64
44
#endif
65
45
}
66
46
 
67
 
/****************************************************************//**
68
 
Allocates large pages memory.
69
 
@return allocated memory */
 
47
/********************************************************************
 
48
Allocates non-cacheable memory. */
 
49
UNIV_INTERN
 
50
void*
 
51
os_mem_alloc_nocache(
 
52
/*=================*/
 
53
                        /* out: allocated memory */
 
54
        ulint   n)      /* in: number of bytes */
 
55
{
 
56
#ifdef __WIN__
 
57
        void*   ptr;
 
58
 
 
59
        ptr = VirtualAlloc(NULL, n, MEM_COMMIT,
 
60
                           PAGE_READWRITE | PAGE_NOCACHE);
 
61
        ut_a(ptr);
 
62
 
 
63
        return(ptr);
 
64
#else
 
65
        return(ut_malloc(n));
 
66
#endif
 
67
}
 
68
 
 
69
/********************************************************************
 
70
Allocates large pages memory. */
70
71
UNIV_INTERN
71
72
void*
72
73
os_mem_alloc_large(
73
74
/*===============*/
74
 
        ulint*  n)                      /*!< in/out: number of bytes */
 
75
                                        /* out: allocated memory */
 
76
        ulint*  n)                      /* in/out: number of bytes */
75
77
{
76
78
        void*   ptr;
77
79
        ulint   size;
109
111
 
110
112
        if (ptr) {
111
113
                *n = size;
112
 
                os_fast_mutex_lock(&ut_list_mutex);
113
114
                ut_total_allocated_memory += size;
114
 
                os_fast_mutex_unlock(&ut_list_mutex);
115
115
# ifdef UNIV_SET_MEM_TO_ZERO
116
116
                memset(ptr, '\0', size);
117
117
# endif
118
 
                UNIV_MEM_ALLOC(ptr, size);
119
118
                return(ptr);
120
119
        }
121
120
 
130
129
 
131
130
        /* Align block size to system page size */
132
131
        ut_ad(ut_is_2pow(system_info.dwPageSize));
133
 
        /* system_info.dwPageSize is only 32-bit. Casting to ulint is required
134
 
        on 64-bit Windows. */
135
132
        size = *n = ut_2pow_round(*n + (system_info.dwPageSize - 1),
136
 
                                  (ulint) system_info.dwPageSize);
 
133
                                  system_info.dwPageSize);
137
134
        ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
138
135
                           PAGE_READWRITE);
139
136
        if (!ptr) {
141
138
                        " Windows error %lu\n",
142
139
                        (ulong) size, (ulong) GetLastError());
143
140
        } else {
144
 
                os_fast_mutex_lock(&ut_list_mutex);
145
141
                ut_total_allocated_memory += size;
146
 
                os_fast_mutex_unlock(&ut_list_mutex);
147
 
                UNIV_MEM_ALLOC(ptr, size);
148
142
        }
149
143
#elif defined __NETWARE__ || !defined OS_MAP_ANON
150
144
        size = *n;
166
160
                        (ulong) size, (ulong) errno);
167
161
                ptr = NULL;
168
162
        } else {
169
 
                os_fast_mutex_lock(&ut_list_mutex);
170
163
                ut_total_allocated_memory += size;
171
 
                os_fast_mutex_unlock(&ut_list_mutex);
172
 
                UNIV_MEM_ALLOC(ptr, size);
173
164
        }
174
165
#endif
175
166
        return(ptr);
176
167
}
177
168
 
178
 
/****************************************************************//**
 
169
/********************************************************************
179
170
Frees large pages memory. */
180
171
UNIV_INTERN
181
172
void
182
173
os_mem_free_large(
183
174
/*==============*/
184
 
        void    *ptr,                   /*!< in: pointer returned by
 
175
        void    *ptr,                   /* in: pointer returned by
185
176
                                        os_mem_alloc_large() */
186
 
        ulint   size)                   /*!< in: size returned by
 
177
        ulint   size)                   /* in: size returned by
187
178
                                        os_mem_alloc_large() */
188
179
{
189
 
        os_fast_mutex_lock(&ut_list_mutex);
190
180
        ut_a(ut_total_allocated_memory >= size);
191
 
        os_fast_mutex_unlock(&ut_list_mutex);
192
181
 
193
182
#if defined HAVE_LARGE_PAGES && defined UNIV_LINUX
194
183
        if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
195
 
                os_fast_mutex_lock(&ut_list_mutex);
196
 
                ut_a(ut_total_allocated_memory >= size);
197
184
                ut_total_allocated_memory -= size;
198
 
                os_fast_mutex_unlock(&ut_list_mutex);
199
 
                UNIV_MEM_FREE(ptr, size);
200
185
                return;
201
186
        }
202
187
#endif /* HAVE_LARGE_PAGES && UNIV_LINUX */
208
193
                        " Windows error %lu\n",
209
194
                        ptr, (ulong) size, (ulong) GetLastError());
210
195
        } else {
211
 
                os_fast_mutex_lock(&ut_list_mutex);
212
 
                ut_a(ut_total_allocated_memory >= size);
213
196
                ut_total_allocated_memory -= size;
214
 
                os_fast_mutex_unlock(&ut_list_mutex);
215
 
                UNIV_MEM_FREE(ptr, size);
216
197
        }
217
198
#elif defined __NETWARE__ || !defined OS_MAP_ANON
218
199
        ut_free(ptr);
222
203
                        " errno %lu\n",
223
204
                        ptr, (ulong) size, (ulong) errno);
224
205
        } else {
225
 
                os_fast_mutex_lock(&ut_list_mutex);
226
 
                ut_a(ut_total_allocated_memory >= size);
227
206
                ut_total_allocated_memory -= size;
228
 
                os_fast_mutex_unlock(&ut_list_mutex);
229
 
                UNIV_MEM_FREE(ptr, size);
230
 
        }
 
207
        }
 
208
#endif
 
209
}
 
210
 
 
211
/********************************************************************
 
212
Sets the priority boost for threads released from waiting within the current
 
213
process. */
 
214
UNIV_INTERN
 
215
void
 
216
os_process_set_priority_boost(
 
217
/*==========================*/
 
218
        ibool   do_boost)       /* in: TRUE if priority boost should be done,
 
219
                                FALSE if not */
 
220
{
 
221
#ifdef __WIN__
 
222
        ibool   no_boost;
 
223
 
 
224
        if (do_boost) {
 
225
                no_boost = FALSE;
 
226
        } else {
 
227
                no_boost = TRUE;
 
228
        }
 
229
 
 
230
#if TRUE != 1
 
231
# error "TRUE != 1"
 
232
#endif
 
233
 
 
234
        /* Does not do anything currently!
 
235
        SetProcessPriorityBoost(GetCurrentProcess(), no_boost);
 
236
        */
 
237
        fputs("Warning: process priority boost setting"
 
238
              " currently not functional!\n",
 
239
              stderr);
 
240
#else
 
241
        UT_NOT_USED(do_boost);
231
242
#endif
232
243
}