Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/traffic_manager/traffic_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@
#include <sys/capability.h>
#endif
#include <grp.h>
#include <atomic>

#define FD_THROTTLE_HEADROOM (128 + 64) // TODO: consolidate with THROTTLE_FD_HEADROOM
#define DIAGS_LOG_FILENAME "manager.log"

#if ATOMIC_INT_LOCK_FREE != 2
#error "Need lock free std::atomic<int>"
#endif

// These globals are still referenced directly by management API.
LocalManager *lmgmt = nullptr;
FileManager *configFiles;
Expand Down Expand Up @@ -100,7 +105,7 @@ static void SignalHandler(int sig);
static void SignalAlrmHandler(int sig);
#endif

static volatile int sigHupNotifier = 0;
static std::atomic<int> sigHupNotifier;
static void SigChldHandler(int sig);

static void
Expand Down Expand Up @@ -704,7 +709,7 @@ main(int argc, const char **argv)
rotateLogs();

// Check for a SIGHUP
if (sigHupNotifier != 0) {
if (sigHupNotifier) {
mgmt_log("[main] Reading Configuration Files due to SIGHUP\n");
Reconfigure();
sigHupNotifier = 0;
Expand Down
11 changes: 6 additions & 5 deletions example/remap/remap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <cstdarg>
#include <cerrno>
#include <pthread.h>
#include <cstdint>
#include <atomic>

#include "ts/ink_defs.h"
#include "ts/ts.h"
Expand Down Expand Up @@ -210,8 +212,8 @@ TSRemapDeleteInstance(void *ih)
delete ri;
}

static volatile unsigned long processing_counter = 0; // sequential counter
static int arg_index = 0;
static std::atomic<uint64_t> processing_counter; // sequential counter
static int arg_index;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure about changing unsigned long to uint64_t. Are we sure unsigned long is not uint32_t on any system that TS runs on?

If you're on a 32-bit architecture, with no bus-locking 64-bit load/store instructions, I'm pretty sure using std::atomic<uint64_t> will generate code with retry loops.

Copy link
Contributor Author

@PSUdaemon PSUdaemon Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) We don't support 32bit
b) This is an example plugin and that is just a counter for monotonically increasing values

TBH, I was sort of just being cute by making that change. There was a comment that said "use a mutex" or similar, so I just added atomics.

/* -------------------------- TSRemapDoRemap -------------------------------- */
TSRemapStatus
Expand All @@ -221,8 +223,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
const char *temp2;
int len, len2, port;
TSMLoc cfield;
unsigned long _processing_counter =
++processing_counter; // one more function call (in real life use mutex to protect this counter)
uint64_t _processing_counter = processing_counter++;

remap_entry *ri = (remap_entry *)ih;
TSDebug(PLUGIN_NAME, "enter");
Expand Down Expand Up @@ -275,7 +276,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
TSHttpTxnArgSet((TSHttpTxn)rh, arg_index, (void *)_processing_counter); // save counter
}
// How to cancel request processing and return error message to the client
// We wiil do it each other request
// We wiil do it every other request
if (_processing_counter & 1) {
char *tmp = (char *)TSmalloc(256);
static int my_local_counter = 0;
Expand Down
2 changes: 1 addition & 1 deletion iocore/aio/AIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int ts_config_with_inkdiskio = 0;
/* structure to hold information about each file descriptor */
AIO_Reqs *aio_reqs[MAX_DISKS_POSSIBLE];
/* number of unique file descriptors in the aio_reqs array */
volatile int num_filedes = 1;
int num_filedes = 1;

// acquire this mutex before inserting a new entry in the aio_reqs array.
// Don't need to acquire this for searching the array
Expand Down
8 changes: 4 additions & 4 deletions iocore/aio/I_AIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ typedef struct io_event ink_io_event_t;
#else

struct ink_aiocb {
int aio_fildes = 0;
volatile void *aio_buf = nullptr; /* buffer location */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be an atomic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this patch is doing is removing volatile, which did not give us thread safety. So this shouldn't really change anything with regard to that. If it should be atomic, that might be another issue.

Copy link
Contributor

@bryancall bryancall Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PSUdaemon We should investigate why each of the variables were volatile and covert them to atomic in this PR. Having the changes to atomics in another PR would make it harder to see what needs/did change to atomic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryancall Should I do the conversions with std::atomic or ink_atomic? I think I'd prefer the former, especially if we plan to remove the latter soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SolidWallOfCode I don't think aio_buf needs to be an atomic. Can you explain why you think otherwise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PSUdaemon I would use std::atomic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, cause that's what I did :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he means on that line. Is this variable shared between threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dragon512 no, it's just a member of a struct for AIO. Each AIO operation should have its own struct. There is a lot of "Oh, we are going to update this then something else has to read it. Better make it volatile so the other thing sees the new data" in the code. Totally useless AFAICT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya this should be removed... it slowing the code down by forcing register load in the pipeline.

size_t aio_nbytes = 0; /* length of transfer */
off_t aio_offset = 0; /* file offset */
int aio_fildes = 0;
void *aio_buf = nullptr; /* buffer location */
size_t aio_nbytes = 0; /* length of transfer */
off_t aio_offset = 0; /* file offset */

int aio_reqprio = 0; /* request priority offset */
int aio_lio_opcode = 0; /* listio operation */
Expand Down
10 changes: 5 additions & 5 deletions iocore/aio/P_AIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ struct AIO_Reqs {
InkAtomicList aio_temp_list;
ink_mutex aio_mutex;
ink_cond aio_cond;
int index; /* position of this struct in the aio_reqs array */
volatile int pending; /* number of outstanding requests on the disk */
volatile int queued; /* total number of aio_todo and http_todo requests */
volatile int filedes; /* the file descriptor for the requests */
volatile int requests_queued;
int index; /* position of this struct in the aio_reqs array */
int pending; /* number of outstanding requests on the disk */
int queued; /* total number of aio_todo and http_todo requests */
int filedes; /* the file descriptor for the requests */
int requests_queued;
};

#endif // AIO_MODE == AIO_MODE_NATIVE
Expand Down
2 changes: 1 addition & 1 deletion iocore/aio/test_AIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum {
};

struct AIO_Device;
volatile int n_accessors = 0;
int n_accessors = 0;
int orig_n_accessors;
AIO_Device *dev[MAX_DISK_THREADS];

Expand Down
34 changes: 17 additions & 17 deletions iocore/cache/Cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,26 @@ int cache_config_compatibility_4_2_0_fixup = 1;

// Globals

RecRawStatBlock *cache_rsb = nullptr;
Cache *theStreamCache = nullptr;
Cache *theCache = nullptr;
CacheDisk **gdisks = nullptr;
int gndisks = 0;
static volatile int initialize_disk = 0;
RecRawStatBlock *cache_rsb = nullptr;
Cache *theStreamCache = nullptr;
Cache *theCache = nullptr;
CacheDisk **gdisks = nullptr;
int gndisks = 0;
static int initialize_disk;
Cache *caches[NUM_CACHE_FRAG_TYPES] = {nullptr};
CacheSync *cacheDirSync = nullptr;
Store theCacheStore;
volatile int CacheProcessor::initialized = CACHE_INITIALIZING;
volatile uint32_t CacheProcessor::cache_ready = 0;
volatile int CacheProcessor::start_done = 0;
bool CacheProcessor::clear = false;
bool CacheProcessor::fix = false;
bool CacheProcessor::check = false;
int CacheProcessor::start_internal_flags = 0;
int CacheProcessor::auto_clear_flag = 0;
int CacheProcessor::initialized = CACHE_INITIALIZING;
uint32_t CacheProcessor::cache_ready = 0;
int CacheProcessor::start_done = 0;
bool CacheProcessor::clear = false;
bool CacheProcessor::fix = false;
bool CacheProcessor::check = false;
int CacheProcessor::start_internal_flags = 0;
int CacheProcessor::auto_clear_flag = 0;
CacheProcessor cacheProcessor;
Vol **gvol = nullptr;
volatile int gnvol = 0;
Vol **gvol = nullptr;
int gnvol = 0;
ClassAllocator<CacheVC> cacheVConnectionAllocator("cacheVConnection");
ClassAllocator<EvacuationBlock> evacuationBlockAllocator("evacuationBlock");
ClassAllocator<CacheRemoveCont> cacheRemoveContAllocator("cacheRemoveCont");
Expand Down Expand Up @@ -277,7 +277,7 @@ static int
update_cache_config(const char * /* name ATS_UNUSED */, RecDataT /* data_type ATS_UNUSED */, RecData data,
void * /* cookie ATS_UNUSED */)
{
volatile int new_value = validate_rww(data.rec_int);
int new_value = validate_rww(data.rec_int);
cache_config_read_while_writer = new_value;

return 0;
Expand Down
2 changes: 1 addition & 1 deletion iocore/cache/CacheHosting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ extern CacheDisk **gdisks;
extern Queue<CacheVol> cp_list;
extern int cp_list_len;
extern ConfigVolumes config_volumes;
extern volatile int gnvol;
extern int gnvol;

extern void cplist_init();
extern int cplist_reconfigure();
Expand Down
2 changes: 1 addition & 1 deletion iocore/cache/CachePagesInternal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern ShowCacheInternal *theshowcacheInternal;
Action *register_ShowCacheInternal(Continuation *c, HTTPHdr *h);

extern Vol **gvol;
extern volatile int gnvol;
extern int gnvol;

// Stat Pages
ShowCacheInternal *theshowcacheInternal = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions iocore/cache/I_Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ struct CacheProcessor : public Processor {
return wait_for_cache;
}

static volatile uint32_t cache_ready;
static volatile int initialized;
static volatile int start_done;
static uint32_t cache_ready;
static int initialized;
static int start_done;
static bool clear;
static bool fix;
static bool check;
Expand Down
4 changes: 2 additions & 2 deletions iocore/cache/P_CacheDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ struct OpenDirEntry {
uint16_t max_writers; // max number of simultaneous writers allowed
bool dont_update_directory; // if set, the first_dir is not updated.
bool move_resident_alt; // if set, single_doc_dir is inserted.
volatile bool reading_vec; // somebody is currently reading the vector
volatile bool writing_vec; // somebody is currently writing the vector
bool reading_vec; // somebody is currently reading the vector
bool writing_vec; // somebody is currently writing the vector

LINK(OpenDirEntry, link);

Expand Down
4 changes: 2 additions & 2 deletions iocore/cache/P_CacheHosting.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ struct CacheHostRecord {

CacheType type;
Vol **vols;
volatile int good_num_vols;
volatile int num_vols;
int good_num_vols;
int num_vols;
int num_initialized;
unsigned short *vol_hash_table;
CacheVol **cp;
Expand Down
10 changes: 5 additions & 5 deletions iocore/cache/P_CacheInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,13 @@ struct Vol;
class CacheHostTable;

struct Cache {
volatile int cache_read_done;
volatile int total_good_nvol;
volatile int total_nvol;
volatile int ready;
int cache_read_done;
int total_good_nvol;
int total_nvol;
int ready;
int64_t cache_size; // in store block size
CacheHostTable *hosttable;
volatile int total_initialized_vol;
int total_initialized_vol;
CacheType scheme;

int open(bool reconfigure, bool fix);
Expand Down
2 changes: 1 addition & 1 deletion iocore/cache/P_CacheTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PinnedDocTable : public Continuation {

struct CacheTestHost {
char *name;
volatile unsigned int xlast_cachable_id;
unsigned int xlast_cachable_id;
double xprev_host_prob;
double xnext_host_prob;

Expand Down
2 changes: 1 addition & 1 deletion iocore/cache/P_CacheVol.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ struct Doc {
// Global Data

extern Vol **gvol;
extern volatile int gnvol;
extern int gnvol;
extern ClassAllocator<OpenDirEntry> openDirEntryAllocator;
extern ClassAllocator<EvacuationBlock> evacuationBlockAllocator;
extern ClassAllocator<EvacuationKey> evacuationKeyAllocator;
Expand Down
2 changes: 1 addition & 1 deletion iocore/eventsystem/I_Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Action
machine.

*/
volatile int cancelled = false;
int cancelled = false;

/**
Cancels the asynchronous operation represented by this action.
Expand Down
2 changes: 1 addition & 1 deletion iocore/eventsystem/I_EThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum ThreadType {
DEDICATED,
};

extern volatile bool shutdown_event_system;
extern bool shutdown_event_system;

/**
Event System specific type of thread.
Expand Down
4 changes: 2 additions & 2 deletions iocore/eventsystem/I_EventProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ class EventProcessor : public Processor
EThread *assign_thread(EventType etype);

EThread *all_dthreads[MAX_EVENT_THREADS];
volatile int n_dthreads = 0; // No. of dedicated threads
volatile int thread_data_used = 0;
int n_dthreads = 0; // No. of dedicated threads
int thread_data_used = 0;

/// Provide container style access to just the active threads, not the entire array.
class active_threads_type
Expand Down
3 changes: 1 addition & 2 deletions iocore/eventsystem/I_Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@

class EThread;
typedef EThread *EThreadPtr;
typedef volatile EThreadPtr VolatileEThreadPtr;

#if DEBUG
inkcoreapi extern void lock_waiting(const SourceLocation &, const char *handler);
Expand Down Expand Up @@ -203,7 +202,7 @@ class ProxyMutex : public RefCountObj
lock. You must not modify or set this value directly.

*/
volatile EThreadPtr thread_holding;
EThreadPtr thread_holding;

int nthread_holding;

Expand Down
2 changes: 1 addition & 1 deletion iocore/eventsystem/UnixEThread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AIOCallback;
#define NO_HEARTBEAT -1
#define THREAD_MAX_HEARTBEAT_MSECONDS 60

volatile bool shutdown_event_system = false;
bool shutdown_event_system = false;

EThread::EThread()
{
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/P_UnixNetState.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Event;
class UnixNetVConnection;

struct NetState {
volatile int enabled;
int enabled;
VIO vio;
Link<UnixNetVConnection> ready_link;
SLink<UnixNetVConnection> enable_link;
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/P_UnixNetVConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class UnixNetVConnection : public NetVConnection
UnixNetVConnection *migrateToCurrentThread(Continuation *c, EThread *t);

Action action_;
volatile int closed;
int closed;
NetState read;
NetState write;

Expand Down
5 changes: 2 additions & 3 deletions iocore/net/UnixNetAccept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
#endif
#define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))

using NetAcceptHandler = int (NetAccept::*)(int, void *);
volatile int dummy_volatile = 0;
int accept_till_done = 1;
using NetAcceptHandler = int (NetAccept::*)(int, void *);
int accept_till_done = 1;

std::vector<NetAccept *> naVec;
static void
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/UnixNetProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// For Stat Pages
#include "StatPages.h"

volatile int net_accept_number = 0;
int net_accept_number = 0;
extern std::vector<NetAccept *> naVec;
NetProcessor::AcceptOptions const NetProcessor::DEFAULT_ACCEPT_OPTIONS;

Expand Down
2 changes: 1 addition & 1 deletion lib/cppapi/Logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct atscppapi::LoggerState : noncopyable {
std::string filename_;
bool add_timestamp_;
bool rename_file_;
volatile Logger::LogLevel level_;
Logger::LogLevel level_;
bool rolling_enabled_;
int rolling_interval_seconds_;
TSTextLogObject text_log_obj_;
Expand Down
8 changes: 4 additions & 4 deletions lib/ts/BaseLogFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ class BaseLogFile
LOG_FILE_COULD_NOT_OPEN_FILE,
};

FILE *m_fp = nullptr;
long m_start_time = time(nullptr);
long m_end_time = 0L;
volatile uint64_t m_bytes_written = 0;
FILE *m_fp = nullptr;
long m_start_time = time(nullptr);
long m_end_time = 0L;
uint64_t m_bytes_written = 0;

private:
// member functions
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/Diags.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Diags
BaseLogFile *stderr_log;

const unsigned int magic;
volatile DiagsConfigState config;
DiagsConfigState config;
DiagsShowLocation show_location;
DiagsCleanupFunc cleanup_func;

Expand Down
Loading