GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix races between PerfEvents::createForThread/destroyForThread (#1848) · async-profiler/async-profiler@95ee0c7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • perfEvents_linux.cpp
    • spinLock.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/perfEvents_linux.cpp‎

Copy file name to clipboardExpand all lines: src/perfEvents_linux.cpp
+12-9Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ int PerfEvents::createForThread(int tid) {
637637
if (fd == -1) {
638638
int err = errno;
639639
Log::warn("perf_event_open for TID %d failed: %s", tid, strerror(err));
640-
_events[tid]._fd = 0;
640+
storeRelease(_events[tid]._fd, 0);
641641
if (isResourceLimit(err) && _current != NULL) {
642642
// Emergency shutdown
643643
stop();
@@ -653,9 +653,6 @@ int PerfEvents::createForThread(int tid) {
653653
page = NULL;
654654
}
655655
}
656-
657-
_events[tid].reset();
658-
_events[tid]._fd = fd;
659656
_events[tid]._page = (struct perf_event_mmap_page*)page;
660657

661658
if (multiplex_state_dirty && fd < MAX_MULTIPLEXED_FD) {
@@ -675,6 +672,7 @@ int PerfEvents::createForThread(int tid) {
675672
err = errno;
676673
Log::warn("perf_event ioctl failed: %s", strerror(err));
677674
} else {
675+
storeRelease(_events[tid]._fd, fd);
678676
return 0;
679677
}
680678

@@ -684,7 +682,7 @@ int PerfEvents::createForThread(int tid) {
684682
_events[tid]._page = NULL;
685683
}
686684
close(fd);
687-
_events[tid]._fd = 0;
685+
storeRelease(_events[tid]._fd, 0);
688686

689687
return err;
690688
}
@@ -695,17 +693,22 @@ void PerfEvents::destroyForThread(int tid) {
695693
}
696694

697695
PerfEvent* event = &_events[tid];
698-
int fd = event->_fd;
699-
if (fd > 0 && __sync_bool_compare_and_swap(&event->_fd, fd, 0)) {
700-
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
701-
close(fd);
696+
int fd = loadAcquire(event->_fd);
697+
if (fd <= 0 || !__sync_bool_compare_and_swap(&event->_fd, fd, -1)) {
698+
return;
702699
}
700+
701+
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
702+
close(fd);
703+
703704
if (event->_page != NULL) {
704705
event->lock();
705706
munmap(event->_page, 2 * OS::page_size);
706707
event->_page = NULL;
707708
event->unlock();
708709
}
710+
711+
storeRelease(event->_fd, 0);
709712
}
710713

711714
u64 PerfEvents::readCounter(siginfo_t* siginfo, void* ucontext) {
Collapse file

‎src/spinLock.h‎

Copy file name to clipboardExpand all lines: src/spinLock.h
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ class SpinLock {
2222
SpinLock(int initial_state = 0) : _lock(initial_state) {
2323
}
2424

25-
void reset() {
26-
_lock = 0;
27-
}
28-
2925
bool tryLock() {
3026
return __sync_bool_compare_and_swap(&_lock, 0, 1);
3127
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.