This is an automated email from the git hooks/post-receive script.
mreynolds pushed a commit to branch rhel-7.4
in repository 389-ds-base.
commit d41993c7828e17ed7f81fa287a7ffc5f7b27b337
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Mon Mar 27 15:40:29 2017 -0400
Revert "Issue 48989 - Overflow in counters and monitor"
This reverts commit eccbf16740b05f76c97e8d6b5d275af0f08cac71.
---
Makefile.am | 4 +-
dirsrvtests/tests/tickets/issue48989_test.py | 57 ----
ldap/servers/plugins/dna/dna.c | 20 +-
ldap/servers/plugins/posix-winsync/posix-winsync.c | 12 +-
ldap/servers/plugins/replication/repl5_init.c | 2 +-
ldap/servers/plugins/replication/repl_extop.c | 2 +-
ldap/servers/plugins/usn/usn.c | 16 +-
ldap/servers/slapd/back-ldbm/monitor.c | 4 +-
ldap/servers/slapd/back-ldbm/perfctrs.c | 12 +-
ldap/servers/slapd/back-ldbm/perfctrs.h | 74 +++--
ldap/servers/slapd/back-ldbm/vlv_srch.h | 2 +-
ldap/servers/slapd/conntable.c | 14 +-
ldap/servers/slapd/entry.c | 4 +-
ldap/servers/slapd/log.c | 13 +-
ldap/servers/slapd/monitor.c | 14 +-
ldap/servers/slapd/slapi-plugin.h | 14 +-
ldap/servers/slapd/slapi_counter.c | 299 +++++++++++++++++++--
ldap/servers/slapd/slapi_counter_sunos_sparcv9.S | 105 ++++++++
ldap/servers/slapd/snmp_collator.c | 2 +-
test/libslapd/counters/atomic.c | 69 -----
test/libslapd/test.c | 2 -
test/test_slapd.h | 4 -
22 files changed, 488 insertions(+), 257 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 982dd28..df4a037 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1222,6 +1222,9 @@ libslapd_la_SOURCES = ldap/servers/slapd/add.c \
$(libavl_a_SOURCES)
libslapd_la_CPPFLAGS = $(AM_CPPFLAGS) $(DSPLUGIN_CPPFLAGS) $(SASL_INCLUDES) @db_inc@
$(SVRCORE_INCLUDES) @kerberos_inc@ @pcre_inc@
+if SPARC
+libslapd_la_SOURCES += ldap/servers/slapd/slapi_counter_sunos_sparcv9.S
+endif
libslapd_la_LIBADD = $(LDAPSDK_LINK) $(SASL_LINK) $(SVRCORE_LINK) $(NSS_LINK)
$(NSPR_LINK) $(KERBEROS_LINK) $(PCRE_LINK) $(THREADLIB) $(SYSTEMD_LINK)
libslapd_la_LDFLAGS = $(AM_LDFLAGS) $(SLAPD_LDFLAGS)
@@ -2001,7 +2004,6 @@ TESTS = test_slapd \
test_slapd_SOURCES = test/main.c \
test/libslapd/test.c \
- test/libslapd/counters/atomic.c \
test/libslapd/pblock/analytics.c \
test/libslapd/pblock/v3_compat.c \
test/libslapd/operation/v3_compat.c
diff --git a/dirsrvtests/tests/tickets/issue48989_test.py
b/dirsrvtests/tests/tickets/issue48989_test.py
deleted file mode 100644
index b4e7a95..0000000
--- a/dirsrvtests/tests/tickets/issue48989_test.py
+++ /dev/null
@@ -1,57 +0,0 @@
-import os
-import time
-import ldap
-import logging
-import pytest
-from lib389.topologies import topology_st
-from lib389._constants import *
-from lib389.properties import *
-from lib389.tasks import *
-from lib389.utils import *
-
-DEBUGGING = False
-
-if DEBUGGING:
- logging.getLogger(__name__).setLevel(logging.DEBUG)
-else:
- logging.getLogger(__name__).setLevel(logging.INFO)
-log = logging.getLogger(__name__)
-
-
-def test_bytessent_overflow(topology_st):
- """
- Issue 48989 - Add 10k entries and run search until the value of bytessent is
- bigger than 2^32 or resets to 0
- """
-
- # Create users
- topology_st.standalone.ldclt.create_users('ou=People,%s' %
- DEFAULT_SUFFIX, min=0, max=10000)
- bytessent = int(topology_st.standalone.search_s(
- 'cn=monitor', ldap.SCOPE_BASE,
attrlist=['bytessent'])[0].getValue('bytessent'))
- bytessent_old = bytessent
-
- while bytessent < 4300000000:
- # Do searches
- topology_st.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- filterstr='(objectClass=*)')
-
- # Read bytessent value from cn=monitor
- bytessent = int(topology_st.standalone.search_s(
- 'cn=monitor', ldap.SCOPE_BASE,
attrlist=['bytessent'])[0].getValue('bytessent'))
-
- if bytessent > bytessent_old:
- bytessent_old = bytessent
- else:
- # If it overflows - test failed
- assert(bytessent > 4294967295)
-
-
-if __name__ == '__main__':
- # Run isolated
- # -s for DEBUG mode
- CURRENT_FILE = os.path.realpath(__file__)
- pytest.main("-s %s" % CURRENT_FILE)
-
-
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index 34011b9..54bbe86 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -2497,7 +2497,7 @@ static int dna_get_next_value(struct configEntry *config_entry,
if ((config_entry->maxval == -1) ||
(nextval <= (config_entry->maxval + config_entry->interval))) {
/* try to set the new next value in the config entry */
- snprintf(next_value, sizeof(next_value),"%" NSPRIu64, nextval);
+ PR_snprintf(next_value, sizeof(next_value),"%" NSPRIu64, nextval);
/* set up our replace modify operation */
replace_val[0] = next_value;
@@ -2565,13 +2565,13 @@ dna_get_shared_config_attr_val(struct configEntry *config_entry,
char *attr, cha
if(slapi_sdn_compare(server->sdn, server_sdn) == 0){
if(strcmp(attr, DNA_REMOTE_BIND_METHOD) == 0){
if (server->remote_bind_method) {
- snprintf(value, DNA_REMOTE_BUFSIZ, "%s",
server->remote_bind_method);
+ PR_snprintf(value, DNA_REMOTE_BUFSIZ, "%s",
server->remote_bind_method);
found = 1;
}
break;
} else if(strcmp(attr, DNA_REMOTE_CONN_PROT) == 0){
if (server->remote_conn_prot) {
- snprintf(value, DNA_REMOTE_BUFSIZ, "%s",
server->remote_conn_prot);
+ PR_snprintf(value, DNA_REMOTE_BUFSIZ, "%s",
server->remote_conn_prot);
found = 1;
}
break;
@@ -2609,7 +2609,7 @@ dna_update_shared_config(struct configEntry *config_entry)
/* We store the number of remaining assigned values
* in the shared config entry. */
- snprintf(remaining_vals, sizeof(remaining_vals),"%" NSPRIu64,
+ PR_snprintf(remaining_vals, sizeof(remaining_vals),"%" NSPRIu64,
config_entry->remaining);
/* set up our replace modify operation */
@@ -2709,7 +2709,7 @@ dna_update_next_range(struct configEntry *config_entry,
int ret = 0;
/* Try to set the new next range in the config entry. */
- snprintf(nextrange_value, sizeof(nextrange_value), "%" NSPRIu64
"-%" NSPRIu64,
+ PR_snprintf(nextrange_value, sizeof(nextrange_value), "%" NSPRIu64
"-%" NSPRIu64,
lower, upper);
/* set up our replace modify operation */
@@ -2778,8 +2778,8 @@ dna_activate_next_range(struct configEntry *config_entry)
int ret = 0;
/* Setup the modify operation for the config entry */
- snprintf(maxval_val, sizeof(maxval_val),"%" NSPRIu64,
config_entry->next_range_upper);
- snprintf(nextval_val, sizeof(nextval_val),"%" NSPRIu64,
config_entry->next_range_lower);
+ PR_snprintf(maxval_val, sizeof(maxval_val),"%" NSPRIu64,
config_entry->next_range_upper);
+ PR_snprintf(nextval_val, sizeof(nextval_val),"%" NSPRIu64,
config_entry->next_range_lower);
maxval_vals[0] = maxval_val;
maxval_vals[1] = 0;
@@ -4411,8 +4411,8 @@ static int dna_extend_exop(Slapi_PBlock *pb)
char highstr[16];
/* Create the exop response */
- snprintf(lowstr, sizeof(lowstr), "%" NSPRIu64, lower);
- snprintf(highstr, sizeof(highstr), "%" NSPRIu64, upper);
+ PR_snprintf(lowstr, sizeof(lowstr), "%" NSPRIu64, lower);
+ PR_snprintf(highstr, sizeof(highstr), "%" NSPRIu64, upper);
range_low.bv_val = lowstr;
range_low.bv_len = strlen(range_low.bv_val);
range_high.bv_val = highstr;
@@ -4588,7 +4588,7 @@ dna_release_range(char *range_dn, PRUint64 *lower, PRUint64 *upper)
*lower = *upper - release + 1;
/* try to set the new maxval in the config entry */
- snprintf(max_value, sizeof(max_value),"%" NSPRIu64, (*lower -
1));
+ PR_snprintf(max_value, sizeof(max_value),"%" NSPRIu64, (*lower
- 1));
/* set up our replace modify operation */
replace_val[0] = max_value;
diff --git a/ldap/servers/plugins/posix-winsync/posix-winsync.c
b/ldap/servers/plugins/posix-winsync/posix-winsync.c
index 63444e5..a7e024d 100644
--- a/ldap/servers/plugins/posix-winsync/posix-winsync.c
+++ b/ldap/servers/plugins/posix-winsync/posix-winsync.c
@@ -234,7 +234,7 @@ sync_acct_disable(void *cbdata, /* the usual domain config data */
{
int ds_is_enabled = 1; /* default to true */
int ad_is_enabled = 1; /* default to true */
- uint64_t adval = 0; /* raw account val from ad entry */
+ unsigned long adval = 0; /* raw account val from ad entry */
int isvirt = 0;
/* get the account lock state of the ds entry */
@@ -270,8 +270,9 @@ sync_acct_disable(void *cbdata, /* the usual domain config data */
if (update_entry) {
slapi_entry_attr_set_ulong(update_entry, "userAccountControl",
adval);
slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
- "<-- sync_acct_disable - %s AD account [%s] - new value is
[%" NSPRIu64 "]\n",
- (ds_is_enabled) ? "enabled" : "disabled",
slapi_entry_get_dn_const(update_entry), adval);
+ "<-- sync_acct_disable - %s AD account [%s] - "
+ "new value is [%ld]\n", (ds_is_enabled) ?
"enabled" : "disabled",
+ slapi_entry_get_dn_const(update_entry), adval);
} else {
/* iterate through the mods - if there is already a mod
for userAccountControl, change it - otherwise, add it */
@@ -326,8 +327,9 @@ sync_acct_disable(void *cbdata, /* the usual domain config data */
mod_bval->bv_len = strlen(acctvalstr);
}
slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
- "<-- sync_acct_disable - %s AD account [%s] - new value is
[%" NSPRIu64 "]\n",
- (ds_is_enabled) ? "enabled" : "disabled",
slapi_entry_get_dn_const(ad_entry), adval);
+ "<-- sync_acct_disable - %s AD account [%s] - "
+ "new value is [%ld]\n", (ds_is_enabled) ?
"enabled" : "disabled",
+ slapi_entry_get_dn_const(ad_entry), adval);
}
}
diff --git a/ldap/servers/plugins/replication/repl5_init.c
b/ldap/servers/plugins/replication/repl5_init.c
index 9549dcf..0945f7b 100644
--- a/ldap/servers/plugins/replication/repl5_init.c
+++ b/ldap/servers/plugins/replication/repl5_init.c
@@ -208,7 +208,7 @@ get_repl_session_id (Slapi_PBlock *pb, char *idstr, CSN **csn)
/* Avoid "Connection is NULL and hence cannot access SLAPI_CONN_ID" */
if (opid) {
slapi_pblock_get (pb, SLAPI_CONN_ID, &connid);
- snprintf (idstr, REPL_SESSION_ID_SIZE, "conn=%" NSPRIu64 "
op=%d",
+ PR_snprintf (idstr, REPL_SESSION_ID_SIZE, "conn=%" NSPRIu64 "
op=%d",
connid, opid);
}
diff --git a/ldap/servers/plugins/replication/repl_extop.c
b/ldap/servers/plugins/replication/repl_extop.c
index 80580f9..948f38d 100644
--- a/ldap/servers/plugins/replication/repl_extop.c
+++ b/ldap/servers/plugins/replication/repl_extop.c
@@ -865,7 +865,7 @@ multimaster_extop_StartNSDS50ReplicationRequest(Slapi_PBlock *pb)
* the session's conn id and op id to identify the the supplier.
*/
/* junkrc = ruv_get_first_id_and_purl(supplier_ruv, &junkrid, &locking_purl);
*/
- snprintf(locking_session, sizeof(locking_session), "conn=%" NSPRIu64 "
id=%d",
+ PR_snprintf(locking_session, sizeof(locking_session), "conn=%" NSPRIu64 "
id=%d",
connid, opid);
locking_purl = &locking_session[0];
if (replica_get_exclusive_access(replica, &isInc, connid, opid,
diff --git a/ldap/servers/plugins/usn/usn.c b/ldap/servers/plugins/usn/usn.c
index 5e67e0a..6fe8d2e 100644
--- a/ldap/servers/plugins/usn/usn.c
+++ b/ldap/servers/plugins/usn/usn.c
@@ -360,7 +360,7 @@ _usn_mod_next_usn(LDAPMod ***mods, Slapi_Backend *be)
/* add next USN to the mods; "be" contains the usn counter */
usn_berval.bv_val = counter_buf;
- snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRIu64,
+ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRIu64,
slapi_counter_get_value(be->be_usn_counter));
usn_berval.bv_len = strlen(usn_berval.bv_val);
bvals[0] = &usn_berval;
@@ -670,7 +670,7 @@ usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter,
/* nsslapd-entryusn-global: on*/
/* root dse shows ...
* lastusn: <num> */
- snprintf(attr, USN_LAST_USN_ATTR_CORE_LEN + 1, "%s", USN_LAST_USN);
+ PR_snprintf(attr, USN_LAST_USN_ATTR_CORE_LEN + 1, "%s", USN_LAST_USN);
for (be = slapi_get_first_backend(&cookie); be;
be = slapi_get_next_backend(cookie)) {
if (be->be_usn_counter) {
@@ -681,10 +681,10 @@ usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter,
/* get a next USN counter from be_usn_counter;
* then minus 1 from it (except if be_usn_counter has value 0) */
if (slapi_counter_get_value(be->be_usn_counter)) {
- snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRIu64,
+ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%"
NSPRIu64,
slapi_counter_get_value(be->be_usn_counter)-1);
} else {
- snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "-1");
+ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "-1");
}
usn_berval.bv_len = strlen(usn_berval.bv_val);
slapi_entry_attr_replace(e, attr, vals);
@@ -693,7 +693,7 @@ usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter,
/* nsslapd-entryusn-global: off (default) */
/* root dse shows ...
* lastusn;<backend>: <num> */
- snprintf(attr, USN_LAST_USN_ATTR_CORE_LEN + 2, "%s;", USN_LAST_USN);
+ PR_snprintf(attr, USN_LAST_USN_ATTR_CORE_LEN + 2, "%s;",
USN_LAST_USN);
attr_subp = attr + USN_LAST_USN_ATTR_CORE_LEN + 1;
for (be = slapi_get_first_backend(&cookie); be;
be = slapi_get_next_backend(cookie)) {
@@ -704,10 +704,10 @@ usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter,
/* get a next USN counter from be_usn_counter;
* then minus 1 from it (except if be_usn_counter has value 0) */
if (slapi_counter_get_value(be->be_usn_counter)) {
- snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRIu64,
+ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%"
NSPRIu64,
slapi_counter_get_value(be->be_usn_counter)-1);
} else {
- snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "-1");
+ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "-1");
}
usn_berval.bv_len = strlen(usn_berval.bv_val);
@@ -716,7 +716,7 @@ usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter,
attr = (char *)slapi_ch_realloc(attr, attr_len);
attr_subp = attr + USN_LAST_USN_ATTR_CORE_LEN;
}
- snprintf(attr_subp, attr_len - USN_LAST_USN_ATTR_CORE_LEN,
+ PR_snprintf(attr_subp, attr_len - USN_LAST_USN_ATTR_CORE_LEN,
"%s", be->be_name);
slapi_entry_attr_replace(e, attr, vals);
}
diff --git a/ldap/servers/slapd/back-ldbm/monitor.c
b/ldap/servers/slapd/back-ldbm/monitor.c
index 757792b..dfcc735 100644
--- a/ldap/servers/slapd/back-ldbm/monitor.c
+++ b/ldap/servers/slapd/back-ldbm/monitor.c
@@ -26,7 +26,7 @@
#define MSETF(_attr, _x) do { \
char tmp_atype[37]; \
- snprintf(tmp_atype, sizeof(tmp_atype), _attr, _x); \
+ PR_snprintf(tmp_atype, sizeof(tmp_atype), _attr, _x); \
MSET(tmp_atype); \
} while (0)
@@ -86,7 +86,7 @@ int ldbm_back_monitor_instance_search(Slapi_PBlock *pb, Slapi_Entry *e,
MSET("entryCacheHits");
sprintf(buf, "%lu", (long unsigned int)tries);
MSET("entryCacheTries");
- sprintf(buf, "%lu", (long unsigned int)(100.0*(double)hits / (double)(tries
> 0 ? tries : 1)));
+ sprintf(buf, "%lu", (unsigned long)(100.0*(double)hits / (double)(tries
> 0 ? tries : 1)));
MSET("entryCacheHitRatio");
sprintf(buf, "%lu", (long unsigned int)size);
MSET("currentEntryCacheSize");
diff --git a/ldap/servers/slapd/back-ldbm/perfctrs.c
b/ldap/servers/slapd/back-ldbm/perfctrs.c
index 5929dea..2bd18bd 100644
--- a/ldap/servers/slapd/back-ldbm/perfctrs.c
+++ b/ldap/servers/slapd/back-ldbm/perfctrs.c
@@ -49,7 +49,7 @@
static void perfctrs_update(perfctrs_private *priv, DB_ENV *db_env);
static void perfctr_add_to_entry( Slapi_Entry *e, char *type,
- uint64_t countervalue );
+ PRUint32 countervalue );
/* Init perf ctrs */
void perfctrs_init(struct ldbminfo *li, perfctrs_private **ret_priv)
@@ -304,13 +304,17 @@ perfctrs_as_entry( Slapi_Entry *e, perfctrs_private *priv, DB_ENV
*db_env )
*/
for ( i = 0; i < SLAPI_LDBM_PERFCTR_AT_MAP_COUNT; ++i ) {
perfctr_add_to_entry( e, perfctr_at_map[i].pam_type,
- *((uint64_t *)((char *)perf + perfctr_at_map[i].pam_offset)));
+ *((PRUint32 *)((char *)perf + perfctr_at_map[i].pam_offset)));
}
}
static void
-perfctr_add_to_entry( Slapi_Entry *e, char *type, uint64_t countervalue )
+perfctr_add_to_entry( Slapi_Entry *e, char *type, PRUint32 countervalue )
{
- slapi_entry_attr_set_ulong( e, type, countervalue );
+ /*
+ * XXXmcs: the following line assumes that long's are 32 bits or larger,
+ * which we assume in other places too I am sure.
+ */
+ slapi_entry_attr_set_ulong( e, type, (unsigned long)countervalue );
}
diff --git a/ldap/servers/slapd/back-ldbm/perfctrs.h
b/ldap/servers/slapd/back-ldbm/perfctrs.h
index 57be1d1..65a7850 100644
--- a/ldap/servers/slapd/back-ldbm/perfctrs.h
+++ b/ldap/servers/slapd/back-ldbm/perfctrs.h
@@ -11,48 +11,46 @@
# include <config.h>
#endif
-#include <inttypes.h>
-
/* Structure definition for performance data */
/* This stuff goes in shared memory, so make sure the packing is consistent */
struct _performance_counters {
- uint64_t sequence_number;
- uint64_t lock_region_wait_rate;
- uint64_t deadlock_rate;
- uint64_t configured_locks;
- uint64_t current_locks;
- uint64_t max_locks;
- uint64_t lockers;
- uint64_t current_lock_objects;
- uint64_t max_lock_objects;
- uint64_t lock_conflicts;
- uint64_t lock_request_rate;
- uint64_t log_region_wait_rate;
- uint64_t log_write_rate;
- uint64_t log_bytes_since_checkpoint;
- uint64_t cache_size_bytes;
- uint64_t page_access_rate;
- uint64_t cache_hit;
- uint64_t cache_try;
- uint64_t page_create_rate;
- uint64_t page_read_rate;
- uint64_t page_write_rate;
- uint64_t page_ro_evict_rate;
- uint64_t page_rw_evict_rate;
- uint64_t hash_buckets;
- uint64_t hash_search_rate;
- uint64_t longest_chain_length;
- uint64_t hash_elements_examine_rate;
- uint64_t pages_in_use;
- uint64_t dirty_pages;
- uint64_t clean_pages;
- uint64_t page_trickle_rate;
- uint64_t cache_region_wait_rate;
- uint64_t active_txns;
- uint64_t commit_rate;
- uint64_t abort_rate;
- uint64_t txn_region_wait_rate;
+ PRUint32 sequence_number;
+ PRUint32 lock_region_wait_rate;
+ PRUint32 deadlock_rate;
+ PRUint32 configured_locks;
+ PRUint32 current_locks;
+ PRUint32 max_locks;
+ PRUint32 lockers;
+ PRUint32 current_lock_objects;
+ PRUint32 max_lock_objects;
+ PRUint32 lock_conflicts;
+ PRUint32 lock_request_rate;
+ PRUint32 log_region_wait_rate;
+ PRUint32 log_write_rate;
+ PRUint32 log_bytes_since_checkpoint;
+ PRUint32 cache_size_bytes;
+ PRUint32 page_access_rate;
+ PRUint32 cache_hit;
+ PRUint32 cache_try;
+ PRUint32 page_create_rate;
+ PRUint32 page_read_rate;
+ PRUint32 page_write_rate;
+ PRUint32 page_ro_evict_rate;
+ PRUint32 page_rw_evict_rate;
+ PRUint32 hash_buckets;
+ PRUint32 hash_search_rate;
+ PRUint32 longest_chain_length;
+ PRUint32 hash_elements_examine_rate;
+ PRUint32 pages_in_use;
+ PRUint32 dirty_pages;
+ PRUint32 clean_pages;
+ PRUint32 page_trickle_rate;
+ PRUint32 cache_region_wait_rate;
+ PRUint32 active_txns;
+ PRUint32 commit_rate;
+ PRUint32 abort_rate;
+ PRUint32 txn_region_wait_rate;
};
typedef struct _performance_counters performance_counters;
diff --git a/ldap/servers/slapd/back-ldbm/vlv_srch.h
b/ldap/servers/slapd/back-ldbm/vlv_srch.h
index 6322f80..d1eba08 100644
--- a/ldap/servers/slapd/back-ldbm/vlv_srch.h
+++ b/ldap/servers/slapd/back-ldbm/vlv_srch.h
@@ -92,7 +92,7 @@ struct vlvIndex
time_t vlv_lastchecked;
/* The number of uses this search has received since start up */
- uint64_t vlv_uses;
+ PRUint32 vlv_uses;
struct backend* vlv_be; /* need backend to remove the index when done */
diff --git a/ldap/servers/slapd/conntable.c b/ldap/servers/slapd/conntable.c
index bcafa4e..004aeae 100644
--- a/ldap/servers/slapd/conntable.c
+++ b/ldap/servers/slapd/conntable.c
@@ -395,7 +395,7 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e)
* 3 = The number of operations attempted that were blocked
* by max threads.
*/
- snprintf(maxthreadbuf, sizeof(maxthreadbuf),
"%d:%"NSPRIu64":%"NSPRIu64"",
+ PR_snprintf(maxthreadbuf, sizeof(maxthreadbuf),
"%d:%"NSPRIu64":%"NSPRIu64"",
maxthreadstate, ct->c[i].c_maxthreadscount,
ct->c[i].c_maxthreadsblocked);
@@ -426,32 +426,32 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e)
PR_ExitMonitor(ct->c[i].c_mutex);
}
- snprintf( buf, sizeof(buf), "%d", nconns );
+ PR_snprintf( buf, sizeof(buf), "%d", nconns );
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "currentconnections", vals );
- snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(num_conns));
+ PR_snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(num_conns));
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "totalconnections", vals );
- snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(conns_in_maxthreads));
+ PR_snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(conns_in_maxthreads));
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "currentconnectionsatmaxthreads", vals
);
- snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(max_threads_count));
+ PR_snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(max_threads_count));
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "maxthreadsperconnhits", vals );
- snprintf( buf, sizeof(buf), "%d", (ct!=NULL?ct->size:0) );
+ PR_snprintf( buf, sizeof(buf), "%d", (ct!=NULL?ct->size:0) );
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "dtablesize", vals );
- snprintf( buf, sizeof(buf), "%d", nreadwaiters );
+ PR_snprintf( buf, sizeof(buf), "%d", nreadwaiters );
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "readwaiters", vals );
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index abacc57..7bbd2f4 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -3088,14 +3088,14 @@ slapi_entry_attr_set_longlong( Slapi_Entry* e, const char *type,
long long l)
}
void
-slapi_entry_attr_set_ulong( Slapi_Entry* e, const char *type, uint64_t l)
+slapi_entry_attr_set_ulong( Slapi_Entry* e, const char *type, unsigned long l)
{
char value[16];
struct berval bv;
struct berval *bvals[2];
bvals[0] = &bv;
bvals[1] = NULL;
- sprintf(value,"%" NSPRIu64, l);
+ sprintf(value,"%lu",l);
bv.bv_val = value;
bv.bv_len = strlen( value );
slapi_entry_attr_replace( e, type, bvals );
diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
index afedd5b..2f43a98 100644
--- a/ldap/servers/slapd/log.c
+++ b/ldap/servers/slapd/log.c
@@ -2327,11 +2327,11 @@ vslapd_log_error(
char buffer[SLAPI_LOG_BUFSIZ];
char sev_name[10];
int blen = TBUFSIZE;
- char *vbuf = NULL;
+ char *vbuf;
int header_len = 0;
int err = 0;
- if (vasprintf(&vbuf, fmt, ap) == -1) {
+ if ((vbuf = PR_vsmprintf(fmt, ap)) == NULL) {
log__error_emergency("CRITICAL: vslapd_log_error, Unable to format
message", 1 , locked);
return -1;
}
@@ -2381,10 +2381,10 @@ vslapd_log_error(
/* blen = strlen(buffer); */
/* This truncates again .... But we have the nice smprintf above! */
if (subsystem == NULL) {
- snprintf (buffer+blen, sizeof(buffer)-blen, "- %s - %s",
+ PR_snprintf (buffer+blen, sizeof(buffer)-blen, "- %s - %s",
get_log_sev_name(sev_level, sev_name), vbuf);
} else {
- snprintf (buffer+blen, sizeof(buffer)-blen, "- %s - %s - %s",
+ PR_snprintf (buffer+blen, sizeof(buffer)-blen, "- %s - %s - %s",
get_log_sev_name(sev_level, sev_name), subsystem, vbuf);
}
@@ -2418,7 +2418,7 @@ vslapd_log_error(
g_set_shutdown( SLAPI_SHUTDOWN_EXIT );
}
- slapi_ch_free_string(&vbuf);
+ PR_smprintf_free (vbuf);
return( 0 );
}
@@ -2520,7 +2520,8 @@ static int vslapd_log_access(char *fmt, va_list ap)
time_t tnl;
/* We do this sooner, because that we we can use the message in other calls */
- if ((vlen = vsnprintf(vbuf, SLAPI_LOG_BUFSIZ, fmt, ap)) == -1){
+ vlen = PR_vsnprintf(vbuf, SLAPI_LOG_BUFSIZ, fmt, ap);
+ if (! vlen) {
log__error_emergency("CRITICAL: vslapd_log_access, Unable to format
message", 1 ,0);
return -1;
}
diff --git a/ldap/servers/slapd/monitor.c b/ldap/servers/slapd/monitor.c
index f1fb38f..0917bc8 100644
--- a/ldap/servers/slapd/monitor.c
+++ b/ldap/servers/slapd/monitor.c
@@ -54,25 +54,25 @@ monitor_info(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter, int *ret
attrlist_replace( &e->e_attrs, "version", vals );
slapi_ch_free( (void **) &val.bv_val );
- val.bv_len = snprintf( buf, sizeof(buf), "%d", g_get_active_threadcnt() );
+ val.bv_len = PR_snprintf( buf, sizeof(buf), "%d", g_get_active_threadcnt() );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "threads", vals );
connection_table_as_entry(the_connection_table, e);
- val.bv_len = snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(ops_initiated) );
+ val.bv_len = PR_snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(ops_initiated) );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "opsinitiated", vals );
- val.bv_len = snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(ops_completed) );
+ val.bv_len = PR_snprintf( buf, sizeof(buf), "%" NSPRIu64,
slapi_counter_get_value(ops_completed) );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "opscompleted", vals );
- val.bv_len = snprintf ( buf, sizeof(buf), "%" NSPRIu64,
g_get_num_entries_sent() );
+ val.bv_len = PR_snprintf ( buf, sizeof(buf), "%" NSPRIu64,
g_get_num_entries_sent() );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "entriessent", vals );
- val.bv_len = snprintf ( buf, sizeof(buf), "%" NSPRIu64, g_get_num_bytes_sent()
);
+ val.bv_len = PR_snprintf ( buf, sizeof(buf), "%" NSPRIu64,
g_get_num_bytes_sent() );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "bytessent", vals );
@@ -88,12 +88,12 @@ monitor_info(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry*
entryAfter, int *ret
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "starttime", vals );
- val.bv_len = snprintf( buf, sizeof(buf), "%d", be_nbackends_public() );
+ val.bv_len = PR_snprintf( buf, sizeof(buf), "%d", be_nbackends_public() );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "nbackends", vals );
#ifdef THREAD_SUNOS5_LWP
- val.bv_len = snprintf( buf, sizeof(buf), "%d", thr_getconcurrency() );
+ val.bv_len = PR_snprintf( buf, sizeof(buf), "%d", thr_getconcurrency() );
val.bv_val = buf;
attrlist_replace( &e->e_attrs, "concurrency", vals );
#endif
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index 725fa1c..1bd8fc8 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -1954,7 +1954,7 @@ void slapi_entry_attr_set_longlong( Slapi_Entry* e, const char
*type, long long
* \param type Attribute type in which you want to set the value.
* \param l Unsigned long value that you want to assign to the attribute.
*/
-void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, uint64_t l);
+void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l);
/**
* Check if an attribute is set in the entry
@@ -6746,12 +6746,12 @@ void slapi_destroy_task(void *arg);
Slapi_Counter *slapi_counter_new(void);
void slapi_counter_init(Slapi_Counter *counter);
void slapi_counter_destroy(Slapi_Counter **counter);
-uint64_t slapi_counter_increment(Slapi_Counter *counter);
-uint64_t slapi_counter_decrement(Slapi_Counter *counter);
-uint64_t slapi_counter_add(Slapi_Counter *counter, uint64_t addvalue);
-uint64_t slapi_counter_subtract(Slapi_Counter *counter, uint64_t subvalue);
-uint64_t slapi_counter_set_value(Slapi_Counter *counter, uint64_t newvalue);
-uint64_t slapi_counter_get_value(Slapi_Counter *counter);
+PRUint64 slapi_counter_increment(Slapi_Counter *counter);
+PRUint64 slapi_counter_decrement(Slapi_Counter *counter);
+PRUint64 slapi_counter_add(Slapi_Counter *counter, PRUint64 addvalue);
+PRUint64 slapi_counter_subtract(Slapi_Counter *counter, PRUint64 subvalue);
+PRUint64 slapi_counter_set_value(Slapi_Counter *counter, PRUint64 newvalue);
+PRUint64 slapi_counter_get_value(Slapi_Counter *counter);
/* Binder-based (connection centric) resource limits */
/*
diff --git a/ldap/servers/slapd/slapi_counter.c b/ldap/servers/slapd/slapi_counter.c
index 4b03a29..c3ac846 100644
--- a/ldap/servers/slapd/slapi_counter.c
+++ b/ldap/servers/slapd/slapi_counter.c
@@ -12,17 +12,38 @@
#include "slap.h"
+#ifdef SOLARIS
+PRUint64 _sparcv9_AtomicSet(PRUint64 *address, PRUint64 newval);
+PRUint64 _sparcv9_AtomicAdd(PRUint64 *address, PRUint64 val);
+PRUint64 _sparcv9_AtomicSub(PRUint64 *address, PRUint64 val);
+#endif
+
#ifdef HPUX
#ifdef ATOMIC_64BIT_OPERATIONS
#include <machine/sys/inline.h>
#endif
#endif
+#ifdef ATOMIC_64BIT_OPERATIONS
+#if defined(LINUX) && !HAVE_64BIT_ATOMIC_OP_FUNCS
+/* On systems that don't have the 64-bit GCC atomic builtins, we need to
+ * implement our own atomic functions using inline assembly code. */
+PRUint64 __sync_add_and_fetch_8(PRUint64 *ptr, PRUint64 addval);
+PRUint64 __sync_sub_and_fetch_8(PRUint64 *ptr, PRUint64 subval);
+#define __sync_add_and_fetch __sync_add_and_fetch_8
+#define __sync_sub_and_fetch __sync_sub_and_fetch_8
+#endif
+#endif /* ATOMIC_64BIT_OPERATIONS */
+
+
/*
* Counter Structure
*/
typedef struct slapi_counter {
- uint64_t value;
+ PRUint64 value;
+#ifndef ATOMIC_64BIT_OPERATIONS
+ Slapi_Mutex *lock;
+#endif
} slapi_counter;
/*
@@ -51,6 +72,13 @@ Slapi_Counter *slapi_counter_new()
void slapi_counter_init(Slapi_Counter *counter)
{
if (counter != NULL) {
+#ifndef ATOMIC_64BIT_OPERATIONS
+ /* Create the lock if necessary. */
+ if (counter->lock == NULL) {
+ counter->lock = slapi_new_mutex();
+ }
+#endif
+
/* Set the value to 0. */
slapi_counter_set_value(counter, 0);
}
@@ -65,6 +93,9 @@ void slapi_counter_init(Slapi_Counter *counter)
void slapi_counter_destroy(Slapi_Counter **counter)
{
if ((counter != NULL) && (*counter != NULL)) {
+#ifndef ATOMIC_64BIT_OPERATIONS
+ slapi_destroy_mutex((*counter)->lock);
+#endif
slapi_ch_free((void **)counter);
}
}
@@ -74,7 +105,7 @@ void slapi_counter_destroy(Slapi_Counter **counter)
*
* Atomically increments a Slapi_Counter.
*/
-uint64_t slapi_counter_increment(Slapi_Counter *counter)
+PRUint64 slapi_counter_increment(Slapi_Counter *counter)
{
return slapi_counter_add(counter, 1);
}
@@ -86,7 +117,7 @@ uint64_t slapi_counter_increment(Slapi_Counter *counter)
* that this will not prevent you from wrapping
* around 0.
*/
-uint64_t slapi_counter_decrement(Slapi_Counter *counter)
+PRUint64 slapi_counter_decrement(Slapi_Counter *counter)
{
return slapi_counter_subtract(counter, 1);
}
@@ -96,20 +127,28 @@ uint64_t slapi_counter_decrement(Slapi_Counter *counter)
*
* Atomically add a value to a Slapi_Counter.
*/
-uint64_t slapi_counter_add(Slapi_Counter *counter, uint64_t addvalue)
+PRUint64 slapi_counter_add(Slapi_Counter *counter, PRUint64 addvalue)
{
- uint64_t newvalue = 0;
+ PRUint64 newvalue = 0;
#ifdef HPUX
- uint64_t prev = 0;
+ PRUint64 prev = 0;
#endif
if (counter == NULL) {
return newvalue;
}
-#ifndef HPUX
- newvalue = __atomic_add_fetch_8(&(counter->value), addvalue,
__ATOMIC_SEQ_CST);
+#ifndef ATOMIC_64BIT_OPERATIONS
+ slapi_lock_mutex(counter->lock);
+ counter->value += addvalue;
+ newvalue = counter->value;
+ slapi_unlock_mutex(counter->lock);
#else
+#ifdef LINUX
+ newvalue = __sync_add_and_fetch(&(counter->value), addvalue);
+#elif defined(SOLARIS)
+ newvalue = _sparcv9_AtomicAdd(&(counter->value), addvalue);
+#elif defined(HPUX)
/* fetchadd only works with values of 1, 4, 8, and 16. In addition, it requires
* it's argument to be an integer constant. */
if (addvalue == 1) {
@@ -134,6 +173,7 @@ uint64_t slapi_counter_add(Slapi_Counter *counter, uint64_t addvalue)
} while (prev != _Asm_cmpxchg(_FASZ_D, _SEM_ACQ, &(counter->value),
newvalue, _LDHINT_NONE));
}
#endif
+#endif /* ATOMIC_64BIT_OPERATIONS */
return newvalue;
}
@@ -144,20 +184,28 @@ uint64_t slapi_counter_add(Slapi_Counter *counter, uint64_t
addvalue)
* Atomically subtract a value from a Slapi_Counter. Note
* that this will not prevent you from wrapping around 0.
*/
-uint64_t slapi_counter_subtract(Slapi_Counter *counter, uint64_t subvalue)
+PRUint64 slapi_counter_subtract(Slapi_Counter *counter, PRUint64 subvalue)
{
- uint64_t newvalue = 0;
+ PRUint64 newvalue = 0;
#ifdef HPUX
- uint64_t prev = 0;
+ PRUint64 prev = 0;
#endif
if (counter == NULL) {
return newvalue;
}
-#ifndef HPUX
- newvalue = __atomic_sub_fetch_8(&(counter->value), subvalue,
__ATOMIC_SEQ_CST);
+#ifndef ATOMIC_64BIT_OPERATIONS
+ slapi_lock_mutex(counter->lock);
+ counter->value -= subvalue;
+ newvalue = counter->value;
+ slapi_unlock_mutex(counter->lock);
#else
+#ifdef LINUX
+ newvalue = __sync_sub_and_fetch(&(counter->value), subvalue);
+#elif defined(SOLARIS)
+ newvalue = _sparcv9_AtomicSub(&(counter->value), subvalue);
+#elif defined(HPUX)
/* fetchadd only works with values of -1, -4, -8, and -16. In addition, it requires
* it's argument to be an integer constant. */
if (subvalue == 1) {
@@ -182,6 +230,7 @@ uint64_t slapi_counter_subtract(Slapi_Counter *counter, uint64_t
subvalue)
} while (prev != _Asm_cmpxchg(_FASZ_D, _SEM_ACQ, &(counter->value),
newvalue, _LDHINT_NONE));
}
#endif
+#endif /* ATOMIC_64BIT_OPERATIONS */
return newvalue;
}
@@ -191,24 +240,76 @@ uint64_t slapi_counter_subtract(Slapi_Counter *counter, uint64_t
subvalue)
*
* Atomically sets the value of a Slapi_Counter.
*/
-uint64_t slapi_counter_set_value(Slapi_Counter *counter, uint64_t newvalue)
+PRUint64 slapi_counter_set_value(Slapi_Counter *counter, PRUint64 newvalue)
{
- uint64_t value = 0;
+ PRUint64 value = 0;
if (counter == NULL) {
return value;
}
-#ifndef HPUX
- __atomic_store_8(&(counter->value), newvalue, __ATOMIC_SEQ_CST);
-#else /* HPUX */
+#ifndef ATOMIC_64BIT_OPERATIONS
+ slapi_lock_mutex(counter->lock);
+ counter->value = newvalue;
+ slapi_unlock_mutex(counter->lock);
+ return newvalue;
+#else
+#ifdef LINUX
+/* Use our own inline assembly for an atomic set if
+ * the builtins aren't available. */
+#if !HAVE_64BIT_ATOMIC_CAS_FUNC
+ /*
+ * %0 = counter->value
+ * %1 = newvalue
+ */
+ __asm__ __volatile__(
+#ifdef CPU_x86
+ /* Save the PIC register */
+ " pushl %%ebx;"
+#endif /* CPU_x86 */
+ /* Put value of counter->value in EDX:EAX */
+ "retryset: movl %0, %%eax;"
+ " movl 4%0, %%edx;"
+ /* Put newval in ECX:EBX */
+ " movl %1, %%ebx;"
+ " movl 4+%1, %%ecx;"
+ /* If EDX:EAX and counter-> are the same,
+ * replace *ptr with ECX:EBX */
+ " lock; cmpxchg8b %0;"
+ " jnz retryset;"
+#ifdef CPU_x86
+ /* Restore the PIC register */
+ " popl %%ebx"
+#endif /* CPU_x86 */
+ : "+o" (counter->value)
+ : "m" (newvalue)
+#ifdef CPU_x86
+ : "memory", "eax", "ecx", "edx",
"cc");
+#else
+ : "memory", "eax", "ebx", "ecx",
"edx", "cc");
+#endif
+
+ return newvalue;
+#else
+ while (1) {
+ value = counter->value;
+ if (__sync_bool_compare_and_swap(&(counter->value), value, newvalue)) {
+ return newvalue;
+ }
+ }
+#endif /* CPU_x86 || !HAVE_DECL___SYNC_ADD_AND_FETCH */
+#elif defined(SOLARIS)
+ _sparcv9_AtomicSet(&(counter->value), newvalue);
+ return newvalue;
+#elif defined(HPUX)
do {
value = counter->value;
/* Put value in a register for cmpxchg to compare against */
_Asm_mov_to_ar(_AREG_CCV, value);
} while (value != _Asm_cmpxchg(_FASZ_D, _SEM_ACQ, &(counter->value), newvalue,
_LDHINT_NONE));
-#endif
return newvalue;
+#endif
+#endif /* ATOMIC_64BIT_OPERATIONS */
}
/*
@@ -216,24 +317,174 @@ uint64_t slapi_counter_set_value(Slapi_Counter *counter, uint64_t
newvalue)
*
* Returns the value of a Slapi_Counter.
*/
-uint64_t slapi_counter_get_value(Slapi_Counter *counter)
+PRUint64 slapi_counter_get_value(Slapi_Counter *counter)
{
- uint64_t value = 0;
+ PRUint64 value = 0;
if (counter == NULL) {
return value;
}
-#ifndef HPUX
- value = __atomic_load_8(&(counter->value), __ATOMIC_SEQ_CST);
-#else /* HPUX */
+#ifndef ATOMIC_64BIT_OPERATIONS
+ slapi_lock_mutex(counter->lock);
+ value = counter->value;
+ slapi_unlock_mutex(counter->lock);
+#else
+#ifdef LINUX
+/* Use our own inline assembly for an atomic get if
+ * the builtins aren't available. */
+#if !HAVE_64BIT_ATOMIC_CAS_FUNC
+ /*
+ * %0 = counter->value
+ * %1 = value
+ */
+ __asm__ __volatile__(
+#ifdef CPU_x86
+ /* Save the PIC register */
+ " pushl %%ebx;"
+#endif /* CPU_x86 */
+ /* Put value of counter->value in EDX:EAX */
+ "retryget: movl %0, %%eax;"
+ " movl 4%0, %%edx;"
+ /* Copy EDX:EAX to ECX:EBX */
+ " movl %%eax, %%ebx;"
+ " movl %%edx, %%ecx;"
+ /* If EDX:EAX and counter->value are the same,
+ * replace *ptr with ECX:EBX */
+ " lock; cmpxchg8b %0;"
+ " jnz retryget;"
+ /* Put retrieved value into value */
+ " movl %%ebx, %1;"
+ " movl %%ecx, 4%1;"
+#ifdef CPU_x86
+ /* Restore the PIC register */
+ " popl %%ebx"
+#endif /* CPU_x86 */
+ : "+o" (counter->value), "=m" (value)
+ :
+#ifdef CPU_x86
+ : "memory", "eax", "ecx", "edx",
"cc");
+#else
+ : "memory", "eax", "ebx", "ecx",
"edx", "cc");
+#endif
+#else
+ while (1) {
+ value = counter->value;
+ if (__sync_bool_compare_and_swap(&(counter->value), value, value)) {
+ break;
+ }
+ }
+#endif /* CPU_x86 || !HAVE_DECL___SYNC_ADD_AND_FETCH */
+#elif defined(SOLARIS)
+ while (1) {
+ value = counter->value;
+ if (value == _sparcv9_AtomicSet(&(counter->value), value)) {
+ break;
+ }
+ }
+#elif defined(HPUX)
do {
value = counter->value;
/* Put value in a register for cmpxchg to compare against */
_Asm_mov_to_ar(_AREG_CCV, value);
} while (value != _Asm_cmpxchg(_FASZ_D, _SEM_ACQ, &(counter->value), value,
_LDHINT_NONE));
#endif
+#endif /* ATOMIC_64BIT_OPERATIONS */
return value;
}
+#ifdef ATOMIC_64BIT_OPERATIONS
+#if defined(LINUX) && !HAVE_64BIT_ATOMIC_OP_FUNCS
+/* On systems that don't have the 64-bit GCC atomic builtins, we need to
+ * implement our own atomic add and subtract functions using inline
+ * assembly code. */
+PRUint64 __sync_add_and_fetch_8(PRUint64 *ptr, PRUint64 addval)
+{
+ PRUint64 retval = 0;
+
+ /*
+ * %0 = *ptr
+ * %1 = retval
+ * %2 = addval
+ */
+ __asm__ __volatile__(
+#ifdef CPU_x86
+ /* Save the PIC register */
+ " pushl %%ebx;"
+#endif /* CPU_x86 */
+ /* Put value of *ptr in EDX:EAX */
+ "retryadd: movl %0, %%eax;"
+ " movl 4%0, %%edx;"
+ /* Put addval in ECX:EBX */
+ " movl %2, %%ebx;"
+ " movl 4+%2, %%ecx;"
+ /* Add value from EDX:EAX to value in ECX:EBX */
+ " addl %%eax, %%ebx;"
+ " adcl %%edx, %%ecx;"
+ /* If EDX:EAX and *ptr are the same, replace ptr with ECX:EBX */
+ " lock; cmpxchg8b %0;"
+ " jnz retryadd;"
+ /* Put new value into retval */
+ " movl %%ebx, %1;"
+ " movl %%ecx, 4%1;"
+#ifdef CPU_x86
+ /* Restore the PIC register */
+ " popl %%ebx"
+#endif /* CPU_x86 */
+ : "+o" (*ptr), "=m" (retval)
+ : "m" (addval)
+#ifdef CPU_x86
+ : "memory", "eax", "ecx", "edx",
"cc");
+#else
+ : "memory", "eax", "ebx", "ecx",
"edx", "cc");
+#endif
+
+ return retval;
+}
+
+PRUint64 __sync_sub_and_fetch_8(PRUint64 *ptr, PRUint64 subval)
+{
+ PRUint64 retval = 0;
+
+ /*
+ * %0 = *ptr
+ * %1 = retval
+ * %2 = subval
+ */
+ __asm__ __volatile__(
+#ifdef CPU_x86
+ /* Save the PIC register */
+ " pushl %%ebx;"
+#endif /* CPU_x86 */
+ /* Put value of *ptr in EDX:EAX */
+ "retrysub: movl %0, %%eax;"
+ " movl 4%0, %%edx;"
+ /* Copy EDX:EAX to ECX:EBX */
+ " movl %%eax, %%ebx;"
+ " movl %%edx, %%ecx;"
+ /* Subtract subval from value in ECX:EBX */
+ " subl %2, %%ebx;"
+ " sbbl 4+%2, %%ecx;"
+ /* If EDX:EAX and ptr are the same, replace *ptr with ECX:EBX */
+ " lock; cmpxchg8b %0;"
+ " jnz retrysub;"
+ /* Put new value into retval */
+ " movl %%ebx, %1;"
+ " movl %%ecx, 4%1;"
+#ifdef CPU_x86
+ /* Restore the PIC register */
+ " popl %%ebx"
+#endif /* CPU_x86 */
+ : "+o" (*ptr), "=m" (retval)
+ : "m" (subval)
+#ifdef CPU_x86
+ : "memory", "eax", "ecx", "edx",
"cc");
+#else
+ : "memory", "eax", "ebx", "ecx",
"edx", "cc");
+#endif
+
+ return retval;
+}
+#endif /* LINUX && !HAVE_64BIT_ATOMIC_OP_FUNCS */
+#endif /* ATOMIC_64BIT_OPERATIONS */
diff --git a/ldap/servers/slapd/slapi_counter_sunos_sparcv9.S
b/ldap/servers/slapd/slapi_counter_sunos_sparcv9.S
new file mode 100644
index 0000000..e582c2a
--- /dev/null
+++ b/ldap/servers/slapd/slapi_counter_sunos_sparcv9.S
@@ -0,0 +1,105 @@
+! BEGIN COPYRIGHT BLOCK
+! The Original Code is the Netscape Portable Runtime (NSPR).
+!
+! The Initial Developer of the Original Code is
+! Netscape Communications Corporation.
+! Portions created by the Initial Developer are Copyright (C) 1998-2000
+! the Initial Developer. All Rights Reserved.
+!
+! The original code has been modified to support 64-bit atomic increments by
+! Red Hat, Inc. These portions are Copyright (C) 2008 Red Hat, Inc. All Rights
+! reserved.
+!
+! License: GPL (version 3 or any later version).
+! See LICENSE for details.
+! END COPYRIGHT BLOCK
+!
+
+#define _ASM 1 /* force to set an assembler code macro _ASM */
+#include <sys/asm_linkage.h>
+
+! ======================================================================
+!
+! Perform the sequence a = b atomically with respect to other
+! fetch-and-stores to location a in a wait-free fashion.
+!
+! usage : old_val = PR_AtomicSet(address, newval)
+!
+! -----------------------
+! Note on REGISTER USAGE:
+! as this is a LEAF procedure, a new stack frame is not created;
+! we use the caller's stack frame so what would normally be %i (input)
+! registers are actually %o (output registers). Also, we must not
+! overwrite the contents of %l (local) registers as they are not
+! assumed to be volatile during calls.
+! -----------------------
+
+ ENTRY(_sparcv9_AtomicSet) ! standard assembler/ELF prologue
+
+retryAS:
+ ldx [%o0], %o2 ! set o2 to the current value
+ mov %o1, %o3 ! set up the new value
+ casx [%o0], %o2, %o3 ! atomically set if o0 hasn't changed
+ cmp %o2, %o3 ! see if we set the value
+ bne retryAS ! if not, try again
+ nop ! empty out the branch pipeline
+ retl ! return back to the caller
+ mov %o3, %o0 ! set the return code to the prev value
+
+ SET_SIZE(_sparcv9_AtomicSet) ! standard assembler/ELF epilogue
+
+!
+! end
+!
+! ======================================================================
+!
+! Perform the sequence a = a + b atomically with respect to other
+! fetch-and-adds to location a in a wait-free fashion.
+!
+! usage : newval = PR_AtomicAdd(address, val)
+! return: the value after addition
+!
+ ENTRY(_sparcv9_AtomicAdd) ! standard assembler/ELF prologue
+
+retryAA:
+ ldx [%o0], %o2 ! set o2 to the current value
+ addx %o2, %o1, %o3 ! calc the new value
+ mov %o3, %o4 ! save the return value
+ casx [%o0], %o2, %o3 ! atomically set if o0 hasn't changed
+ cmp %o2, %o3 ! see if we set the value
+ bne retryAA ! if not, try again
+ nop ! empty out the branch pipeline
+ retl ! return back to the caller
+ mov %o4, %o0 ! set the return code to the new value
+
+ SET_SIZE(_sparcv9_AtomicAdd) ! standard assembler/ELF epilogue
+
+!
+! end
+!
+! ======================================================================
+!
+! Perform the sequence a = a - b atomically with respect to other
+! fetch-and-subs to location a in a wait-free fashion.
+!
+! usage : newval = PR_AtomicSub(address, val)
+! return: the value after addition
+!
+ ENTRY(_sparcv9_AtomicSub) ! standard assembler/ELF prologue
+
+retryAU:
+ ldx [%o0], %o2 ! set o2 to the current value
+ subx %o2, %o1, %o3 ! calc the new value
+ mov %o3, %o4 ! save the return value
+ casx [%o0], %o2, %o3 ! atomically set if o0 hasn't changed
+ cmp %o2, %o3 ! see if we set the value
+ bne retryAU ! if not, try again
+ nop ! empty out the branch pipeline
+ retl ! return back to the caller
+ mov %o4, %o0 ! set the return code to the new value
+
+ SET_SIZE(_sparcv9_AtomicSub) ! standard assembler/ELF epilogue
+
+!
+! end
+!
diff --git a/ldap/servers/slapd/snmp_collator.c b/ldap/servers/slapd/snmp_collator.c
index b0c873d..841922f 100644
--- a/ldap/servers/slapd/snmp_collator.c
+++ b/ldap/servers/slapd/snmp_collator.c
@@ -711,7 +711,7 @@ static void
add_counter_to_value(Slapi_Entry *e, const char *type, PRUint64 countervalue)
{
char value[40];
- snprintf(value,sizeof(value),"%" NSPRIu64, countervalue);
+ PR_snprintf(value,sizeof(value),"%" NSPRIu64, countervalue);
slapi_entry_attr_set_charptr( e, type, value);
}
diff --git a/test/libslapd/counters/atomic.c b/test/libslapd/counters/atomic.c
deleted file mode 100644
index 72fad88..0000000
--- a/test/libslapd/counters/atomic.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * Copyright (C) 2017 Red Hat, Inc.
- * All rights reserved.
- *
- * License: GPL (version 3 or any later version).
- * See LICENSE for details.
- * END COPYRIGHT BLOCK **/
-
-#include "../../test_slapd.h"
-
-void
-test_libslapd_counters_atomic_usage(void **state __attribute__((unused))) {
- Slapi_Counter *tc = slapi_counter_new();
-
- uint64_t value = 0;
- /* Check that it starts as 0 */
- value = slapi_counter_get_value(tc);
- assert_true(value == 0);
- /* Increment */
- slapi_counter_increment(tc);
- value = slapi_counter_get_value(tc);
- assert_true(value == 1);
- /* add */
- slapi_counter_add(tc, 100);
- value = slapi_counter_get_value(tc);
- assert_true(value == 101);
- /* set */
- slapi_counter_set_value(tc, 200);
- value = slapi_counter_get_value(tc);
- assert_true(value == 200);
- /* dec */
- slapi_counter_decrement(tc);
- value = slapi_counter_get_value(tc);
- assert_true(value == 199);
- /* sub */
- slapi_counter_subtract(tc, 99);
- value = slapi_counter_get_value(tc);
- assert_true(value == 100);
- /* init */
- slapi_counter_init(tc);
- value = slapi_counter_get_value(tc);
- assert_true(value == 0);
-
-
- slapi_counter_destroy(&tc);
-
- /* We could attempt a more complex thread test later? */
-
-}
-
-void
-test_libslapd_counters_atomic_overflow(void **state __attribute__((unused))) {
- Slapi_Counter *tc = slapi_counter_new();
- /* This is intmax ... */
- uint32_t value_32 = 0xFFFFFFFF;
- uint64_t value = 0;
-
- slapi_counter_set_value(tc, (uint64_t)value_32);
- value = slapi_counter_get_value(tc);
- assert_true(value == (uint64_t)value_32);
-
- slapi_counter_increment(tc);
- value = slapi_counter_get_value(tc);
- assert_true(value != 0);
- assert_true(value > (uint64_t)value_32);
-
- slapi_counter_destroy(&tc);
-}
-
diff --git a/test/libslapd/test.c b/test/libslapd/test.c
index 6e1171a..37d5543 100644
--- a/test/libslapd/test.c
+++ b/test/libslapd/test.c
@@ -24,8 +24,6 @@ run_libslapd_tests (void) {
cmocka_unit_test(test_libslapd_pblock_v3c_original_target_dn),
cmocka_unit_test(test_libslapd_pblock_v3c_target_uniqueid),
cmocka_unit_test(test_libslapd_operation_v3c_target_spec),
- cmocka_unit_test(test_libslapd_counters_atomic_usage),
- cmocka_unit_test(test_libslapd_counters_atomic_overflow),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/test/test_slapd.h b/test/test_slapd.h
index b8f1aba..02eefdd 100644
--- a/test/test_slapd.h
+++ b/test/test_slapd.h
@@ -37,8 +37,4 @@ void test_libslapd_pblock_v3c_target_uniqueid(void **state);
/* libslapd-operation-v3_compat */
void test_libslapd_operation_v3c_target_spec(void **state);
-/* libslapd-counters-atomic */
-
-void test_libslapd_counters_atomic_usage(void **state);
-void test_libslapd_counters_atomic_overflow(void **state);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.