Skip to content
This repository was archived by the owner on Aug 19, 2020. It is now read-only.

Commit 9fadb47

Browse files
committed
Make compile with NVM_EXT work with precompiler version 14.
Fixed bug in NVM_ALIGN macro. Persistent structs are initialized before the address is put into a pointer to persistent struct so that nvm_verify calls all work. Use shapeof() rather than presume the global name of an nvm_type definition under NVM_EXT compile. Use a better hash function in nvm_pick_mutex. Implement nvm_get_mutex to get a mutex by index from an nvm_mutex_array. Add const where needed. Lack of a root object indicates an uninitialized region rather than an invalid USID in nvm_region struct. Change the USID for nvm_region since this library version does not work with previous region files.
1 parent a39229e commit 9fadb47

19 files changed

+748
-546
lines changed

nvmd/nvm_heap.c

Lines changed: 75 additions & 73 deletions
Large diffs are not rendered by default.

nvmd/nvm_heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,10 @@ extern "C"
448448
*/
449449
#ifdef NVM_EXT
450450
#define NVM_ALLOC(heap, type, count) \
451-
((type^)nvm_alloc((heap), shapeof(type), (count))
451+
((type^)nvm_alloc((heap), shapeof(type), (count)))
452452
#else
453453
#define NVM_ALLOC(heap, type, count) \
454-
((type*)nvm_alloc((heap), shapeof(type), (count))
454+
((type*)nvm_alloc((heap), shapeof(type), (count)))
455455
#endif //NVM_EXT
456456

457457
/**

nvmd/nvm_heap0.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ extern "C"
9898
nvm_blk_srp back; // ^nvm_blk
9999
};
100100
typedef struct nvm_link nvm_link;
101+
extern const nvm_type nvm_type_nvm_link;
101102
#endif //NVM_EXT
102-
extern const nvm_type nvm_type_nvm_link; //#
103103

104104
/**
105105
* This is a list of doubly linked nvm_blk structs. It is embedded in

nvmd/nvm_locks.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ nvm_mutex_array *nvm_create_mutex_array(
387387
#ifdef NVM_EXT
388388
nvm_mutex ^nvm_pick_mutex@(
389389
nvm_mutex_array ^array,
390-
void ^ptr
390+
const void ^ptr
391391
)
392392
{
393393
/* get the region for the array and ptr from the current transaction */
@@ -408,15 +408,15 @@ nvm_mutex ^nvm_pick_mutex@(
408408
* address. */
409409
size_t offset = (uint8_t^)ptr - (uint8_t^)rg;
410410

411-
/* divide offset by a prime that is less than the alignment of heap
412-
* allocation to get an even distribution across the mutexes. Use that
411+
/* divide offset by a prime that is less than the alignment of most
412+
* pointers to get an even distribution across the mutexes. Use that
413413
* to select the mutex. */
414-
return (nvm_mutex ^)%array=>mutexes[(offset/61) % array=>count];
414+
return (nvm_mutex ^)%array=>mutexes[(offset/7) % array=>count];
415415
}
416416
#else
417417
nvm_mutex *nvm_pick_mutex(
418418
nvm_mutex_array *array,
419-
void *ptr
419+
const void *ptr
420420
)
421421
{
422422
/* get the region for the array and ptr from the current transaction */
@@ -437,12 +437,13 @@ nvm_mutex *nvm_pick_mutex(
437437
* address. */
438438
size_t offset = (uint8_t*)ptr - (uint8_t*)rg;
439439

440-
/* divide offset by a prime that is less than the alignment of heap
441-
* allocation to get an even distribution across the mutexes. Use that
440+
/* divide offset by a prime that is less than the alignment of most
441+
* pointers to get an even distribution across the mutexes. Use that
442442
* to select the mutex. */
443-
return (nvm_mutex *)&array->mutexes[(offset/61) % array->count];
443+
return (nvm_mutex *)&array->mutexes[(offset/7) % array->count];
444444
}
445445
#endif //NVM_EXT
446+
446447
/**
447448
* Find the wait table bucket for an NVM mutex and acquire its mutex.
448449
* @param tx

nvmd/nvm_locks.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,40 @@ NVM_SRP(nvm_mutex) // define self-relative pointer operations
191191
#ifdef NVM_EXT
192192
nvm_mutex ^nvm_pick_mutex@(
193193
nvm_mutex_array ^array,
194-
void ^ptr
194+
const void ^ptr
195195
);
196196
#else
197197
nvm_mutex *nvm_pick_mutex(
198198
nvm_mutex_array *array,
199-
void *ptr
199+
const void *ptr
200+
);
201+
#endif //NVM_EXT
202+
203+
/**
204+
* Get one mutex from a mutex array by an index into the array. A pointer
205+
* to the mutex is returned. If the index is past the end of the array a
206+
* null pointer is returned. This must be called in a transaction. Any
207+
* errors will fire an assert. This is useful for acquiring all the
208+
* mutexes one at a time.
209+
*
210+
* @param[in] array
211+
* The mutex array to pick from
212+
*
213+
* @param[in] index
214+
* Index into the array of the mutex to return
215+
*
216+
* @return
217+
* Pointer to the chosen mutex or null if there is none
218+
*/
219+
#ifdef NVM_EXT
220+
nvm_mutex ^nvm_get_mutex@(
221+
nvm_mutex_array ^array,
222+
uint32_t index
223+
);
224+
#else
225+
nvm_mutex *nvm_get_mutex(
226+
nvm_mutex_array *array,
227+
uint32_t index
200228
);
201229
#endif //NVM_EXT
202230

@@ -221,7 +249,6 @@ NVM_SRP(nvm_mutex) // define self-relative pointer operations
221249
);
222250
#endif //NVM_EXT
223251

224-
225252
/**
226253
* This acquires an NVM lock and hangs it on the current transaction. The
227254
* lock may be a shared or exclusive lock. If the lock is successfully

nvmd/nvm_misc.c

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void nvm_thread_fini(void)
251251
*/
252252
#ifdef NVM_EXT
253253
void nvm_flush(
254-
void ^ptr,
254+
const void ^ptr,
255255
size_t bytes
256256
)
257257
{
@@ -313,7 +313,7 @@ void nvm_flush(
313313
}
314314
#else
315315
void nvm_flush(
316-
void *ptr,
316+
const void *ptr,
317317
size_t bytes
318318
)
319319
{
@@ -384,7 +384,7 @@ void nvm_flush(
384384
*/
385385
#ifdef NVM_EXT
386386
void nvm_flush1(
387-
void ^ptr
387+
const void ^ptr
388388
)
389389
{
390390
nvm_thread_data *td = nvm_get_thread_data();
@@ -434,7 +434,7 @@ void nvm_flush1(
434434
}
435435
#else
436436
void nvm_flush1(
437-
void *ptr
437+
const void *ptr
438438
)
439439
{
440440
nvm_thread_data *td = nvm_get_thread_data();
@@ -484,87 +484,6 @@ void nvm_flush1(
484484
}
485485
#endif //NVM_EXT
486486

487-
/**
488-
* This does an immediate flush of a range of bytes rather than just saving
489-
* the address for flushing before next persist. This has less overhead
490-
* than scheduling the flush, but the data is lost from the processor cache.
491-
*
492-
* @param[in] ptr
493-
* The is the first byte of NVM to flush from caches
494-
*
495-
* @param[in] bytes
496-
* The number of bytes to flush. Pass zero to flush just one cache line.
497-
*/
498-
#ifdef NVM_EXT
499-
void nvm_flushi(
500-
void ^ptr,
501-
size_t bytes
502-
)
503-
{
504-
/* Optimize case of just one cache line */
505-
if (bytes == 0)
506-
{
507-
nvms_flush((uint64_t)ptr);
508-
return;
509-
}
510-
511-
/* need to get the cache line size to decide how many cache lines need
512-
* flushing. */
513-
nvm_app_data *ad = nvm_get_app_data();
514-
uint64_t clsz = ad->params.cache_line; // cache line size
515-
516-
/* Align to a cache line boundary to ensure all cache lines are covered */
517-
uint64_t addr = (uint64_t)ptr;
518-
uint64_t off = addr & (clsz - 1);
519-
addr -= off;
520-
bytes += off;
521-
522-
/* loop flushing one cache line each time around. */
523-
while (1)
524-
{
525-
nvms_flush(addr);
526-
if (bytes <= clsz)
527-
return;
528-
addr += clsz;
529-
bytes -= clsz;
530-
}
531-
}
532-
#else
533-
void nvm_flushi(
534-
void *ptr,
535-
size_t bytes
536-
)
537-
{
538-
/* Optimize case of just one cache line */
539-
if (bytes == 0)
540-
{
541-
nvms_flush((uint64_t)ptr);
542-
return;
543-
}
544-
545-
/* need to get the cache line size to decide how many cache lines need
546-
* flushing. */
547-
nvm_app_data *ad = nvm_get_app_data();
548-
uint64_t clsz = ad->params.cache_line; // cache line size
549-
550-
/* Align to a cache line boundary to ensure all cache lines are covered */
551-
uint64_t addr = (uint64_t)ptr;
552-
uint64_t off = addr & (clsz - 1);
553-
addr -= off;
554-
bytes += off;
555-
556-
/* loop flushing one cache line each time around. */
557-
while (1)
558-
{
559-
nvms_flush(addr);
560-
if (bytes <= clsz)
561-
return;
562-
addr += clsz;
563-
bytes -= clsz;
564-
}
565-
}
566-
#endif //NVM_EXT
567-
568487
/**
569488
* This is a barrier that ensures all previous stores to NVM by the calling
570489
* thread are actually persistent when it returns. On some systems it is
@@ -670,7 +589,6 @@ void nvm_longjmp(
670589
nvms_assert_fail("Bad nvm_jmp_buf for nmv_longjmp");
671590
}
672591

673-
674592
/* Abort and end transactions until we are at the same depth as the
675593
* nvm_setjmp. */
676594
while (depth > buf->depth)
@@ -860,6 +778,6 @@ uint16_t nvm_cas2(
860778
return ret;
861779
}
862780
#endif
863-
//TODO+ before calling nvms_corrupt mark the nvm_region as failed for
864-
// corruption. Have a status that is the mechanism of the last detach:
865-
// clean, assert, or corruption
781+
//TODO+ before calling nvms_corrupt mark the nvm_region as failed for
782+
//TODO+ corruption. Have a status that is the mechanism of the last detach:
783+
//TODO+ clean, assert, or corruption

0 commit comments

Comments
 (0)