2 * Copyright (C) 2012 - Simon Marchi <simon.marchi@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
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., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <sys/resource.h>
30 static bool pthread_attr_init_done
;
31 static pthread_attr_t tattr
;
32 static pthread_mutex_t tattr_lock
= PTHREAD_MUTEX_INITIALIZER
;
35 size_t default_get_channel_subbuf_size(void)
37 return max(_DEFAULT_CHANNEL_SUBBUF_SIZE
, PAGE_SIZE
);
41 size_t default_get_metadata_subbuf_size(void)
43 return max(DEFAULT_METADATA_SUBBUF_SIZE
, PAGE_SIZE
);
47 size_t default_get_kernel_channel_subbuf_size(void)
49 return max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
, PAGE_SIZE
);
53 size_t default_get_ust_pid_channel_subbuf_size(void)
55 return max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE
, PAGE_SIZE
);
59 size_t default_get_ust_uid_channel_subbuf_size(void)
61 return max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE
, PAGE_SIZE
);
65 pthread_attr_t
*default_pthread_attr(void)
71 pthread_mutex_lock(&tattr_lock
);
73 /* Return cached value. */
74 if (pthread_attr_init_done
) {
78 /* Get system stack size limits. */
79 ret
= getrlimit(RLIMIT_STACK
, &rlim
);
84 DBG("Stack size limits: soft %lld, hard %lld bytes",
85 (long long) rlim
.rlim_cur
,
86 (long long) rlim
.rlim_max
);
88 /* Get pthread default thread stack size. */
89 ret
= pthread_attr_getstacksize(&tattr
, &ptstacksize
);
91 PERROR("pthread_attr_getstacksize");
94 DBG("Default pthread stack size is %zu bytes", ptstacksize
);
96 /* Check if the default pthread stack size honors ulimits. */
97 if (ptstacksize
< rlim
.rlim_cur
) {
98 DBG("Your libc doesn't honor stack size limits, setting thread stack size to soft limit (%lld bytes)",
99 (long long) rlim
.rlim_cur
);
101 /* Create pthread_attr_t struct with ulimit stack size. */
102 ret
= pthread_attr_setstacksize(&tattr
, rlim
.rlim_cur
);
104 PERROR("pthread_attr_setstacksize");
109 /* Enable cached value. */
110 pthread_attr_init_done
= true;
112 pthread_mutex_unlock(&tattr_lock
);
115 pthread_mutex_unlock(&tattr_lock
);
116 WARN("Failed to initialize pthread attributes, using libc defaults.");