* Solaris Porting LAyer Tests (SPLAT) Read/Writer Lock Tests.
\*****************************************************************************/
+#include <sys/random.h>
#include <sys/rwlock.h>
#include <sys/taskq.h>
-#include <sys/random.h>
+#include <linux/delay.h>
+#include <linux/mm_compat.h>
#include "splat-internal.h"
#define SPLAT_RWLOCK_NAME "rwlock"
#define SPLAT_RWLOCK_TEST5_DESC "Write downgrade"
#define SPLAT_RWLOCK_TEST6_ID 0x0706
-#define SPLAT_RWLOCK_TEST6_NAME "rw_tryupgrade"
-#define SPLAT_RWLOCK_TEST6_DESC "Read upgrade"
+#define SPLAT_RWLOCK_TEST6_NAME "rw_tryupgrade-1"
+#define SPLAT_RWLOCK_TEST6_DESC "rwsem->count value"
+
+#define SPLAT_RWLOCK_TEST7_ID 0x0707
+#define SPLAT_RWLOCK_TEST7_NAME "rw_tryupgrade-2"
+#define SPLAT_RWLOCK_TEST7_DESC "Read upgrade"
#define SPLAT_RWLOCK_TEST_MAGIC 0x115599DDUL
#define SPLAT_RWLOCK_TEST_NAME "rwlock_test"
/* The first thread will be the writer */
if (i == 0)
- rwt[i].rwt_thread = kthread_create(splat_rwlock_wr_thr,
+ rwt[i].rwt_thread = spl_kthread_create(splat_rwlock_wr_thr,
&rwt[i], "%s/%d", SPLAT_RWLOCK_TEST_NAME, i);
else
- rwt[i].rwt_thread = kthread_create(splat_rwlock_rd_thr,
+ rwt[i].rwt_thread = spl_kthread_create(splat_rwlock_rd_thr,
&rwt[i], "%s/%d", SPLAT_RWLOCK_TEST_NAME, i);
if (!IS_ERR(rwt[i].rwt_thread)) {
/* Create several threads allowing tasks to race with each other */
tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, num_online_cpus(),
- maxclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE);
+ defclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE);
if (tq == NULL) {
rc = -ENOMEM;
goto out;
* rwlock is implemented right this will never happy, that's a pass.
*/
for (i = 0; i < tq_count; i++) {
- if (!taskq_dispatch(tq,splat_rwlock_test2_func,rwp,TQ_SLEEP)) {
+ if (taskq_dispatch(tq, splat_rwlock_test2_func, rwp,
+ TQ_SLEEP) == TASKQID_INVALID) {
splat_vprint(file, SPLAT_RWLOCK_TEST2_NAME,
"Failed to queue task %d\n", i);
rc = -EINVAL;
rw_enter(&rwp->rw_rwlock, holder_type);
id = taskq_dispatch(tq, splat_rwlock_test4_func, rwp, TQ_SLEEP);
- if (id == 0) {
+ if (id == TASKQID_INVALID) {
splat_vprint(rwp->rw_file, SPLAT_RWLOCK_TEST4_NAME, "%s",
"taskq_dispatch() failed\n");
rc = -EINVAL;
if (rwp == NULL)
return -ENOMEM;
- tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, 1, maxclsyspri,
+ tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, 1, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE);
if (tq == NULL) {
rc = -ENOMEM;
splat_init_rw_priv(rwp, file);
rw_enter(&rwp->rw_rwlock, RW_READER);
- if (!RW_READ_HELD(&rwp->rw_rwlock)) {
+ if (RWSEM_COUNT(SEM(&rwp->rw_rwlock)) !=
+ SPL_RWSEM_SINGLE_READER_VALUE) {
+ splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME,
+ "We assumed single reader rwsem->count "
+ "should be %ld, but is %ld\n",
+ (long int)SPL_RWSEM_SINGLE_READER_VALUE,
+ (long int)RWSEM_COUNT(SEM(&rwp->rw_rwlock)));
+ rc = -ENOLCK;
+ goto out;
+ }
+ rw_exit(&rwp->rw_rwlock);
+
+ rw_enter(&rwp->rw_rwlock, RW_WRITER);
+ if (RWSEM_COUNT(SEM(&rwp->rw_rwlock)) !=
+ SPL_RWSEM_SINGLE_WRITER_VALUE) {
splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME,
+ "We assumed single writer rwsem->count "
+ "should be %ld, but is %ld\n",
+ (long int)SPL_RWSEM_SINGLE_WRITER_VALUE,
+ (long int)RWSEM_COUNT(SEM(&rwp->rw_rwlock)));
+ rc = -ENOLCK;
+ goto out;
+ }
+ rc = 0;
+ splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME, "%s",
+ "rwsem->count same as we assumed\n");
+out:
+ rw_exit(&rwp->rw_rwlock);
+ rw_destroy(&rwp->rw_rwlock);
+ kfree(rwp);
+
+ return rc;
+}
+
+static int
+splat_rwlock_test7(struct file *file, void *arg)
+{
+ rw_priv_t *rwp;
+ int rc;
+
+ rwp = (rw_priv_t *)kmalloc(sizeof(*rwp), GFP_KERNEL);
+ if (rwp == NULL)
+ return -ENOMEM;
+
+ splat_init_rw_priv(rwp, file);
+
+ rw_enter(&rwp->rw_rwlock, RW_READER);
+ if (!RW_READ_HELD(&rwp->rw_rwlock)) {
+ splat_vprint(file, SPLAT_RWLOCK_TEST7_NAME,
"rwlock should be read lock: %d\n",
RW_READ_HELD(&rwp->rw_rwlock));
rc = -ENOLCK;
goto out;
}
-#if defined(CONFIG_RWSEM_GENERIC_SPINLOCK)
/* With one reader upgrade should never fail. */
rc = rw_tryupgrade(&rwp->rw_rwlock);
if (!rc) {
- splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME,
+ splat_vprint(file, SPLAT_RWLOCK_TEST7_NAME,
"rwlock failed upgrade from reader: %d\n",
RW_READ_HELD(&rwp->rw_rwlock));
rc = -ENOLCK;
}
if (RW_READ_HELD(&rwp->rw_rwlock) || !RW_WRITE_HELD(&rwp->rw_rwlock)) {
- splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME, "rwlock should "
+ splat_vprint(file, SPLAT_RWLOCK_TEST7_NAME, "rwlock should "
"have 0 (not %d) reader and 1 (not %d) writer\n",
RW_READ_HELD(&rwp->rw_rwlock),
RW_WRITE_HELD(&rwp->rw_rwlock));
}
rc = 0;
- splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME, "%s",
+ splat_vprint(file, SPLAT_RWLOCK_TEST7_NAME, "%s",
"rwlock properly upgraded\n");
-#else
- rc = 0;
- splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME, "%s",
- "rw_tryupgrade() is disabled for this arch\n");
-#endif
out:
rw_exit(&rwp->rw_rwlock);
rw_destroy(&rwp->rw_rwlock);
SPLAT_RWLOCK_TEST5_ID, splat_rwlock_test5);
SPLAT_TEST_INIT(sub, SPLAT_RWLOCK_TEST6_NAME, SPLAT_RWLOCK_TEST6_DESC,
SPLAT_RWLOCK_TEST6_ID, splat_rwlock_test6);
+ SPLAT_TEST_INIT(sub, SPLAT_RWLOCK_TEST7_NAME, SPLAT_RWLOCK_TEST7_DESC,
+ SPLAT_RWLOCK_TEST7_ID, splat_rwlock_test7);
return sub;
}
splat_rwlock_fini(splat_subsystem_t *sub)
{
ASSERT(sub);
+ SPLAT_TEST_FINI(sub, SPLAT_RWLOCK_TEST7_ID);
SPLAT_TEST_FINI(sub, SPLAT_RWLOCK_TEST6_ID);
SPLAT_TEST_FINI(sub, SPLAT_RWLOCK_TEST5_ID);
SPLAT_TEST_FINI(sub, SPLAT_RWLOCK_TEST4_ID);