Commit Graph

41 Commits

Author SHA1 Message Date
Matan Breizman
23c33f69ff src: sed -i 's/WITH_SEASTAR/WITH_CRIMSON/'
Signed-off-by: Matan Breizman <mbreizma@redhat.com>
2025-04-03 07:53:15 +00:00
Patrick Donnelly
7de5af59c2
common: cache pthread names
This provides common ceph entrypoints for the pthread_[gs]name functions which
will also cache a thread_local copy. This also removes the pthread_t parameter
which precipitated the bug i50743.

Obviously, the overall goal here is to avoid system calls.

See-also: https://tracker.ceph.com/issues/50743
Fixes: 0be8d01c9d
Fixes: https://tracker.ceph.com/issues/68691
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
2024-10-25 10:24:05 -04:00
Milind Changire
0be8d01c9d
log: thread name save/fetch infra
* pthread name is saved in a thread_local storage
* the thread_local name is copied into Entry object's ctor
* Log::dump_recent() reads the thread name from the Entry
  object's data member when dumping logs

Fixes: https://tracker.ceph.com/issues/50743
Signed-off-by: Milind Changire <mchangir@redhat.com>
2024-10-15 17:03:52 +05:30
Lucian Petrut
129fa17caa common: avoid using pthread native handle if not available
Especially when targeting Windows, llvm may not necessarily
use pthreads for std::thread. In this case, we must not use the
"native" thread handle with the pthreads API.

We'll update the ceph_pthread_getname and ceph_pthread_setname
wrappers, adding a new one: ceph_pthread_kill.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
2023-08-30 12:59:00 +00:00
Ilya Dryomov
f6d1de553d Revert "common/Thread: make _entry_func noexcept"
This reverts commit 41142c93a7.
With g++ 8 noexcept here does more harm than good.  See the previous
patch for details.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2021-08-07 14:18:29 +02:00
Adam C. Emerson
41142c93a7 common/Thread: make _entry_func noexcept
Under the GNU system, thread cancellation takes the form of an
exception thrown from the cancellation point, so that the stack
unwinds and destructors are called. The thread entrypoints thus have
what is effectively a catch (...) that terminates on everything but
the thread cancellation exception.

Unfortunately this means the stack has been unwound and we have no
backtrace with which to debug.

Wrapping the actual entry point in noexcept means we call terminate
and get our backtrace as soon as the exception is thrown, assuming it
doesn't get caught by something in the middle.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
2021-01-11 16:05:22 -05:00
Kefu Chai
cafc6f3575 crimson/os: do not configure seastar allocator for alien threads
4cd2b00d2a allows us to colocate seastar
allocator used by seastar reactors and libc allocator used by alien threads,
there is no need to configure seastar allocator for alien thread
anymore.

this change partially reverts

- f7715b86ef
- b55919071f

Signed-off-by: Kefu Chai <kchai@redhat.com>
2020-11-09 14:47:39 +08:00
Adam C. Emerson
4cec019d5e common/Thread: Don't store pointer to thread_name
Having Thread::create store a pointer to a string that is passed to
ceph_pthread_setname in Thread::entry_wrapper can lead to using a
pointer in the calling thread's stack that gets freed before use.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
2020-09-08 22:09:40 -04:00
Radoslaw Zarzynski
b55919071f common/Thread: configure Seastar's memory allocator.
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
2020-06-23 10:16:31 +02:00
Lucian Petrut
61227dfbaf common: stub certain modules and functions on Windows
We're going to stub certain modules and functions for Windows builds.
Some of them will be implemented in subsequent commits, some are platform
specific and will be skipped.

Modules:
* module.c
* subprocess.cc
* blkdev.cc
* dns_resolve.cc
* numa.cc
* syslog.h
* statvfs.h
* libblk
* neorados

Functions:
x signal functions
x fork
x chown
* socketpair_cloexec
* dump_open_fds
* run_cmd
* is_symlink
* CInode::d_type
* nbd commands

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
2020-06-04 15:52:16 +00:00
Sage Weil
39304caf95 common: remove unused ioprio thread/wq infrastructure
This is all now obsolete, with no remaining users.

Move ceph_gettid into Thread.{cc,h}

Signed-off-by: Sage Weil <sage@redhat.com>
2018-10-23 08:29:02 -05:00
Adam C. Emerson
eb59c69674 cleanup: Replace always-false assertions with abort
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
2018-08-27 10:27:22 -04:00
Adam C. Emerson
851813d434 common: Use ceph_assert for asserts
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
2018-08-27 09:09:01 -04:00
Adam C. Emerson
6e98d33ce7 common: Add make_named_thread
To allow us to make a std::thread with a name.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
2018-02-16 12:41:41 -05:00
Jos Collin
5bc0e3448a common: Remove redundant includes
Fixes: http://tracker.ceph.com/issues/19883 (Partially)

Signed-off-by: Jos Collin <jcollin@redhat.com>
2017-05-17 06:49:19 +05:30
Yan, Zheng
1fb15a210a compat: define ceph_pthread_{set,get}name()
pthread_setname_np() exists on OSX, but it only accepts a sinlge
argument. Defining a two parameters version pthread_setname_np()
does not work.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
2016-07-18 15:01:32 +08:00
Willem Jan Withagen
62be9268de compat.h: added a set of extras for FreeBSD <> Linux compatability
If this file is used, it is wise to include it a fist include file
at the top of the code.

Things added to compat.h:
 - ENODATA versus ENOATTR
   This is a very tricky one since ENOATTR is also defined in boost,
   but with a totally diferent value again. We need to make sure
   that the same value is used alt all places.
 - O_DSYNC(freeBSD) versus O_SYNC(Linux)
   fortunately they have the same value.
 - HOST_NAME_MAX is undefined in FreeBSD
   So hardcoded to the value that Linux uses
 - pthread_set_name_np(FreeBSD) versus pthread_setname_np(Linux)
   and the NON-Posix code lives in a separate include file
 - Some compatiblility code for CLOCK_MONOTONIC_COARSE to rewite
   to the FreeBSD equivalent CLOCK_MONOTONIC_FAST

compat.h is added to:
 * src/common/Thread.cc
 * src/common/obj_bencher.cc
 * src/crush/CrushLocation.cc
 * src/include/compat.h
 * src/include/rados/librados.h
 * src/os/filestore/FileStore.cc
 * src/test/system/systest_runnable.cc

Signed-off-by: Willem Jan Withagen <wjw@digiware.nl>
2016-05-25 12:12:43 +02:00
xie xingguo
7b33156b80 common: thread: allow set_affinity() to return a error code
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
2016-03-12 19:32:43 +08:00
Igor Podoski
f22a09705d Bugfix: set thread name will fail, when running as differnt user.
When using setuid/setgid, main thread don't have access to
/proc/self/task/[tid]/comm, which is owned by newly created
thread (root).

To fix this, pthread_setname_np() was moved to newly created
thread, and now it changes name for itself.

Signed-off-by: Igor Podoski <igor.podoski@ts.fujitsu.com>
2016-02-29 13:05:29 +01:00
Igor Podoski
4a4b447e35 threads: add thread names
Adding names to threads simplifies cpu usage realtime tracking
e.g. top -H -p <OSD_PID>

This commit changes Thread.create() method forcing to pass thread name.

Signed-off-by: Igor Podoski <igor.podoski@ts.fujitsu.com>
2016-01-05 15:15:36 +01:00
zqkkqz
9471bb838a Common/Thread: pthread_attr_destroy(thread_attr) when done with it
When a thread attributes object is no longer required, it should be destroyed using the
pthread_attr_destroy() function. Destroying a thread attributes object has no effect on threads that were created using that object.

Fixes: #12570
Signed-off-by: zqkqkz zheng.qiankun@h3c.com
2015-08-07 10:55:44 +08:00
Piotr Dałek
614ac0f4e3 Thread.cc: remove malloc/free pair
There's no need for mallocing pthread_attr_t in Thread::try_create(),
it can be located on stack as it is freed in same function. This reduces
pressure put on memory manager.

Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
2015-07-17 12:43:52 +02:00
Michal Jarzabek
3b5620d969 common/Thread: added const to 2 functions
Changed get_thread_id and am_self to const member functions

Signed-off-by: Michal Jarzabek <stiopa@gmail.com>
2015-07-02 21:08:17 +01:00
John Spray
fe23c6c5e6 common/Thread: print msg on join errors
Signed-off-by: John Spray <john.spray@redhat.com>
2015-06-25 16:19:24 +01:00
Haomai Wang
b0c30f6743 Thread.cc: Make set_affinity private and correct behavior
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
2015-03-20 11:00:56 +08:00
Haomai Wang
b70bd6def7 Thread: Support set_affinity to bind core
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
2015-03-16 00:12:44 +08:00
Michal Jarzabek
e6410ebf39 added some consts
Signed-off-by: Michal Jarzabek <stiopa@gmail.com>
2014-11-25 20:58:04 +00:00
Loic Dachary
c7e4c0bfe7 common: do not set ioprio if pid is not set
Signed-off-by: Loic Dachary <loic-201408@dachary.org>
2014-10-07 14:09:17 +02:00
Sage Weil
1b8741022c common/Thread: allow io priority to be set for a Thread
Ideally, set this before starting the thread.  If you set it after, we
could potentially race with create() itself.

Signed-off-by: Sage Weil <sage@inktank.com>
2014-06-23 09:01:55 -07:00
Yehuda Sadeh
7eb29aeec6 check malloc return values
There were a few places where we didn't check malloc return code.

Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
2012-05-20 15:12:33 -07:00
Sage Weil
c03b852187 thread: remove get_num_threads() static
This looks in /proc to count threads.  Kludgey and no longer needed.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
2012-05-03 20:01:02 -07:00
Sage Weil
46f330d01c Merge branch 'master' into wip-freebsd 2011-10-25 14:54:16 -07:00
Sage Weil
f7ec9f79f7 thread: whitespace
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
2011-10-11 11:16:50 -07:00
Stanislav Sedov
3e0122c9bf Change PAGE_MASK/PAGE_SIZE definitions to CEPH_PAGE_MASK/CEPH_PAGE_SIZE
so they won't interfere with system definitions.

Signed-off-by:	Stanislav Sedov <stas@FreeBSD.org>
2011-10-04 17:34:41 -07:00
Sage Weil
cf862c65fd assert: use our assert
Signed-off-by: Sage Weil <sage@newdream.net>
2011-08-31 10:00:51 -07:00
Sage Weil
43daec44eb thread: detach()
Signed-off-by: Sage Weil <sage@newdream.net>
2011-08-02 11:40:16 -07:00
Colin Patrick McCabe
105a991468 Add more debugging for pthread_create failures
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
2011-07-25 11:19:01 -07:00
Colin Patrick McCabe
209d1407fb Thread.cc: deglobalize
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
2011-06-21 11:40:20 -07:00
Colin Patrick McCabe
823eb2670a Thread.cc: clean up
Don't implement everything in the header file. It slows down compilation
and usually runtime.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
2011-06-20 16:17:19 -07:00
Greg Farnum
29b5ae0c04 simplemessenger: Fix num_threads bug printout.
Also add documentation to get_num_threads since its contract
changed significantly.

Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
2011-02-16 15:07:01 -08:00
Colin Patrick McCabe
6fb416b083 common: thread: get number of threads from /proc
The kernel knows how many threads we have; just ask it. One less atomic
variable to carry around.

We will eventually have to avoid doing this check for non-daemon code,
but that's a separate issue.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
2011-02-15 11:02:03 -08:00