Whamcloud - gitweb
LU-6142 lustre: ptlrpc: don't use list_for_each_entry_safe unnecessarily.
[fs/lustre-release.git] / lustre / ptlrpc / nrs_tbf.c
index d5fab11..32adf79 100644 (file)
@@ -31,8 +31,6 @@
  *
  */
 
-#ifdef HAVE_SERVER_SUPPORT
-
 /**
  * \addtogoup nrs
  * @{
@@ -132,7 +130,7 @@ nrs_tbf_cli_reset_value(struct nrs_tbf_head *head,
        struct nrs_tbf_rule *rule = cli->tc_rule;
 
        cli->tc_rpc_rate = rule->tr_rpc_rate;
-       cli->tc_nsecs = rule->tr_nsecs;
+       cli->tc_nsecs = rule->tr_nsecs_per_rpc;
        cli->tc_depth = rule->tr_depth;
        cli->tc_ntoken = rule->tr_depth;
        cli->tc_check_time = ktime_to_ns(ktime_get());
@@ -140,8 +138,8 @@ nrs_tbf_cli_reset_value(struct nrs_tbf_head *head,
        cli->tc_rule_generation = rule->tr_generation;
 
        if (cli->tc_in_heap)
-               cfs_binheap_relocate(head->th_binheap,
-                                    &cli->tc_node);
+               binheap_relocate(head->th_binheap,
+                                &cli->tc_node);
 }
 
 static void
@@ -302,8 +300,7 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
        memcpy(rule->tr_name, start->tc_name, strlen(start->tc_name));
        rule->tr_rpc_rate = start->u.tc_start.ts_rpc_rate;
        rule->tr_flags = start->u.tc_start.ts_rule_flags;
-       rule->tr_nsecs = NSEC_PER_SEC;
-       do_div(rule->tr_nsecs, rule->tr_rpc_rate);
+       rule->tr_nsecs_per_rpc = NSEC_PER_SEC / rule->tr_rpc_rate;
        rule->tr_depth = tbf_depth;
        atomic_set(&rule->tr_ref, 1);
        INIT_LIST_HEAD(&rule->tr_cli_list);
@@ -350,7 +347,7 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
                head->th_rule = rule;
        }
 
-       CDEBUG(D_RPCTRACE, "TBF starts rule@%p rate %llu gen %llu\n",
+       CDEBUG(D_RPCTRACE, "TBF starts rule@%p rate %u gen %llu\n",
               rule, rule->tr_rpc_rate, rule->tr_generation);
 
        return 0;
@@ -417,8 +414,7 @@ nrs_tbf_rule_change_rate(struct ptlrpc_nrs_policy *policy,
                return -ENOENT;
 
        rule->tr_rpc_rate = rate;
-       rule->tr_nsecs = NSEC_PER_SEC;
-       do_div(rule->tr_nsecs, rule->tr_rpc_rate);
+       rule->tr_nsecs_per_rpc = NSEC_PER_SEC / rule->tr_rpc_rate;
        rule->tr_generation++;
        nrs_tbf_rule_put(rule);
 
@@ -515,7 +511,7 @@ nrs_tbf_command(struct ptlrpc_nrs_policy *policy,
  * \retval 1 e1 < e2
  */
 static int
-tbf_cli_compare(struct cfs_binheap_node *e1, struct cfs_binheap_node *e2)
+tbf_cli_compare(struct binheap_node *e1, struct binheap_node *e2)
 {
        struct nrs_tbf_client *cli1;
        struct nrs_tbf_client *cli2;
@@ -540,7 +536,7 @@ tbf_cli_compare(struct cfs_binheap_node *e1, struct cfs_binheap_node *e2)
 /**
  * TBF binary heap operations
  */
-static struct cfs_binheap_ops nrs_tbf_heap_ops = {
+static struct binheap_ops nrs_tbf_heap_ops = {
        .hop_enter      = NULL,
        .hop_exit       = NULL,
        .hop_compare    = tbf_cli_compare,
@@ -632,7 +628,7 @@ nrs_tbf_jobid_hash_lookup(struct cfs_hash *hs,
        if (hnode == NULL)
                return NULL;
 
-       cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
+       cli = container_of(hnode, struct nrs_tbf_client, tc_hnode);
        if (!list_empty(&cli->tc_lru))
                list_del_init(&cli->tc_lru);
        return cli;
@@ -688,9 +684,8 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
        struct cfs_hash         *hs = head->th_cli_hash;
        struct nrs_tbf_bucket   *bkt;
        int                      hw;
-       struct list_head        zombies;
+       LIST_HEAD(zombies);
 
-       INIT_LIST_HEAD(&zombies);
        cfs_hash_bd_get(hs, &cli->tc_jobid, &bd);
        bkt = cfs_hash_bd_extra_get(hs, &bd);
        if (!cfs_hash_bd_dec_and_lock(hs, &bd, &cli->tc_ref))
@@ -716,8 +711,8 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
        cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
 
        while (!list_empty(&zombies)) {
-               cli = container_of0(zombies.next,
-                                   struct nrs_tbf_client, tc_lru);
+               cli = container_of(zombies.next,
+                                  struct nrs_tbf_client, tc_lru);
                list_del_init(&cli->tc_lru);
                nrs_tbf_cli_fini(cli);
        }
@@ -807,7 +802,7 @@ nrs_tbf_jobid_list_free(struct list_head *jobid_list)
        list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
                OBD_FREE(jobid->tj_id, strlen(jobid->tj_id) + 1);
                list_del(&jobid->tj_linkage);
-               OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
+               OBD_FREE_PTR(jobid);
        }
 }
 
@@ -817,13 +812,13 @@ nrs_tbf_jobid_list_add(struct cfs_lstr *id, struct list_head *jobid_list)
        struct nrs_tbf_jobid *jobid;
        char *ptr;
 
-       OBD_ALLOC(jobid, sizeof(struct nrs_tbf_jobid));
+       OBD_ALLOC_PTR(jobid);
        if (jobid == NULL)
                return -ENOMEM;
 
        OBD_ALLOC(jobid->tj_id, id->ls_len + 1);
        if (jobid->tj_id == NULL) {
-               OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
+               OBD_FREE_PTR(jobid);
                return -ENOMEM;
        }
 
@@ -1003,7 +998,7 @@ static int nrs_tbf_jobid_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_jobid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_jobids_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -1208,7 +1203,7 @@ static int nrs_tbf_nid_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_nid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_nids_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -1399,7 +1394,7 @@ nrs_tbf_cli_hash_lookup(struct cfs_hash *hs, struct cfs_hash_bd *bd,
        if (hnode == NULL)
                return NULL;
 
-       cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
+       cli = container_of(hnode, struct nrs_tbf_client, tc_hnode);
        if (!list_empty(&cli->tc_lru))
                list_del_init(&cli->tc_lru);
        return cli;
@@ -1697,9 +1692,8 @@ nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *cli)
        struct cfs_hash         *hs = head->th_cli_hash;
        struct nrs_tbf_bucket   *bkt;
        int                      hw;
-       struct list_head         zombies;
+       LIST_HEAD(zombies);
 
-       INIT_LIST_HEAD(&zombies);
        cfs_hash_bd_get(hs, &cli->tc_key, &bd);
        bkt = cfs_hash_bd_extra_get(hs, &bd);
        if (!cfs_hash_bd_dec_and_lock(hs, &bd, &cli->tc_ref))
@@ -1724,8 +1718,8 @@ nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *cli)
        cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
 
        while (!list_empty(&zombies)) {
-               cli = container_of0(zombies.next,
-                                   struct nrs_tbf_client, tc_lru);
+               cli = container_of(zombies.next,
+                                  struct nrs_tbf_client, tc_lru);
                list_del_init(&cli->tc_lru);
                nrs_tbf_cli_fini(cli);
        }
@@ -1840,7 +1834,7 @@ nrs_tbf_expression_parse(struct cfs_lstr *src, struct list_head *cond_list)
        struct cfs_lstr field;
        int rc = 0;
 
-       OBD_ALLOC(expr, sizeof(struct nrs_tbf_expression));
+       OBD_ALLOC_PTR(expr);
        if (expr == NULL)
                return -ENOMEM;
 
@@ -1903,7 +1897,7 @@ nrs_tbf_conjunction_parse(struct cfs_lstr *src, struct list_head *cond_list)
        struct cfs_lstr expr;
        int rc = 0;
 
-       OBD_ALLOC(conjunction, sizeof(struct nrs_tbf_conjunction));
+       OBD_ALLOC_PTR(conjunction);
        if (conjunction == NULL)
                return -ENOMEM;
 
@@ -2063,7 +2057,7 @@ nrs_tbf_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_generic_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s %s %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s %s %u, ref %d\n", rule->tr_name,
                   rule->tr_conds_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -2186,7 +2180,6 @@ nrs_tbf_opcode_startup(struct ptlrpc_nrs_policy *policy,
        if (head->th_cli_hash == NULL)
                return -ENOMEM;
 
-       start.u.tc_start.ts_opcodes = NULL;
        start.u.tc_start.ts_opcodes_str = "*";
 
        start.u.tc_start.ts_rpc_rate = tbf_rate;
@@ -2269,7 +2262,7 @@ nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
                        break;
        }
 
-       if (rc == 0)
+       if (rc == 0 && bitmaptr)
                *bitmaptr = opcodes;
        else
                CFS_FREE_BITMAP(opcodes);
@@ -2279,9 +2272,6 @@ nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
 
 static void nrs_tbf_opcode_cmd_fini(struct nrs_tbf_cmd *cmd)
 {
-       if (cmd->u.tc_start.ts_opcodes)
-               CFS_FREE_BITMAP(cmd->u.tc_start.ts_opcodes);
-
        if (cmd->u.tc_start.ts_opcodes_str)
                OBD_FREE(cmd->u.tc_start.ts_opcodes_str,
                         strlen(cmd->u.tc_start.ts_opcodes_str) + 1);
@@ -2308,7 +2298,7 @@ static int nrs_tbf_opcode_parse(struct nrs_tbf_cmd *cmd, char *id)
        /* parse opcode list */
        rc = nrs_tbf_opcode_list_parse(cmd->u.tc_start.ts_opcodes_str,
                                       strlen(cmd->u.tc_start.ts_opcodes_str),
-                                      &cmd->u.tc_start.ts_opcodes);
+                                      NULL);
        if (rc)
                nrs_tbf_opcode_cmd_fini(cmd);
 
@@ -2341,7 +2331,7 @@ static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy,
                strlen(start->u.tc_start.ts_opcodes_str) + 1);
 
        /* Default rule '*' */
-       if (start->u.tc_start.ts_opcodes == NULL)
+       if (strcmp(start->u.tc_start.ts_opcodes_str, "*") == 0)
                return 0;
 
        rc = nrs_tbf_opcode_list_parse(rule->tr_opcodes_str,
@@ -2357,7 +2347,7 @@ static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_opcode_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_opcodes_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -2672,7 +2662,7 @@ nrs_tbf_id_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_id_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_ids_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -2794,10 +2784,10 @@ static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg)
        head->th_ops = ops;
        head->th_type_flag = type;
 
-       head->th_binheap = cfs_binheap_create(&nrs_tbf_heap_ops,
-                                             CBH_FLAG_ATOMIC_GROW, 4096, NULL,
-                                             nrs_pol2cptab(policy),
-                                             nrs_pol2cptid(policy));
+       head->th_binheap = binheap_create(&nrs_tbf_heap_ops,
+                                         CBH_FLAG_ATOMIC_GROW, 4096, NULL,
+                                         nrs_pol2cptab(policy),
+                                         nrs_pol2cptid(policy));
        if (head->th_binheap == NULL)
                GOTO(out_free_head, rc = -ENOMEM);
 
@@ -2813,7 +2803,7 @@ static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg)
        policy->pol_private = head;
        return 0;
 out_free_heap:
-       cfs_binheap_destroy(head->th_binheap);
+       binheap_destroy(head->th_binheap);
 out_free_head:
        OBD_FREE_PTR(head);
 out:
@@ -2846,8 +2836,8 @@ static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy)
        }
        LASSERT(list_empty(&head->th_list));
        LASSERT(head->th_binheap != NULL);
-       LASSERT(cfs_binheap_is_empty(head->th_binheap));
-       cfs_binheap_destroy(head->th_binheap);
+       LASSERT(binheap_is_empty(head->th_binheap));
+       binheap_destroy(head->th_binheap);
        OBD_FREE_PTR(head);
        nrs->nrs_throttling = 0;
        wake_up(&policy->pol_nrs->nrs_svcpt->scp_waitq);
@@ -2885,7 +2875,7 @@ static int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy,
         */
        case NRS_CTL_TBF_RD_RULE: {
                struct nrs_tbf_head *head = policy->pol_private;
-               struct seq_file *m = (struct seq_file *) arg;
+               struct seq_file *m = arg;
                struct ptlrpc_service_part *svcpt;
 
                svcpt = policy->pol_nrs->nrs_svcpt;
@@ -2963,7 +2953,7 @@ static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy,
                        struct nrs_tbf_rule *rule;
 
                        CDEBUG(D_RPCTRACE,
-                              "TBF class@%p rate %llu sequence %d, "
+                              "TBF class@%p rate %u sequence %d, "
                               "rule flags %d, head sequence %d\n",
                               cli, cli->tc_rpc_rate,
                               cli->tc_rule_sequence,
@@ -3052,14 +3042,14 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
        struct nrs_tbf_head       *head = policy->pol_private;
        struct ptlrpc_nrs_request *nrq = NULL;
        struct nrs_tbf_client     *cli;
-       struct cfs_binheap_node   *node;
+       struct binheap_node       *node;
 
        assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
 
        if (!peek && policy->pol_nrs->nrs_throttling)
                return NULL;
 
-       node = cfs_binheap_root(head->th_binheap);
+       node = binheap_root(head->th_binheap);
        if (unlikely(node == NULL))
                return NULL;
 
@@ -3109,18 +3099,18 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                        cli->tc_check_time = now;
                        list_del_init(&nrq->nr_u.tbf.tr_list);
                        if (list_empty(&cli->tc_list)) {
-                               cfs_binheap_remove(head->th_binheap,
-                                                  &cli->tc_node);
+                               binheap_remove(head->th_binheap,
+                                              &cli->tc_node);
                                cli->tc_in_heap = false;
                        } else {
                                if (!(rule->tr_flags & NTRS_REALTIME))
                                        cli->tc_deadline = now + cli->tc_nsecs;
-                               cfs_binheap_relocate(head->th_binheap,
-                                                    &cli->tc_node);
+                               binheap_relocate(head->th_binheap,
+                                                &cli->tc_node);
                        }
                        CDEBUG(D_RPCTRACE,
-                              "TBF dequeues: class@%p rate %llu gen %llu "
-                              "token %llu, rule@%p rate %llu gen %llu\n",
+                              "TBF dequeues: class@%p rate %u gen %llu "
+                              "token %llu, rule@%p rate %u gen %llu\n",
                               cli, cli->tc_rpc_rate,
                               cli->tc_rule_generation, cli->tc_ntoken,
                               cli->tc_rule, cli->tc_rule->tr_rpc_rate,
@@ -3131,9 +3121,9 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                        if (rule->tr_flags & NTRS_REALTIME) {
                                cli->tc_deadline = deadline;
                                cli->tc_nsecs_resid = old_resid;
-                               cfs_binheap_relocate(head->th_binheap,
-                                                    &cli->tc_node);
-                               if (node != cfs_binheap_root(head->th_binheap))
+                               binheap_relocate(head->th_binheap,
+                                                &cli->tc_node);
+                               if (node != binheap_root(head->th_binheap))
                                        return nrs_tbf_req_get(policy,
                                                               peek, force);
                        }
@@ -3173,7 +3163,7 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
        if (list_empty(&cli->tc_list)) {
                LASSERT(!cli->tc_in_heap);
                cli->tc_deadline = cli->tc_check_time + cli->tc_nsecs;
-               rc = cfs_binheap_insert(head->th_binheap, &cli->tc_node);
+               rc = binheap_insert(head->th_binheap, &cli->tc_node);
                if (rc == 0) {
                        cli->tc_in_heap = true;
                        nrq->nr_u.tbf.tr_sequence = head->th_sequence++;
@@ -3202,8 +3192,8 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
 
        if (rc == 0)
                CDEBUG(D_RPCTRACE,
-                      "TBF enqueues: class@%p rate %llu gen %llu "
-                      "token %llu, rule@%p rate %llu gen %llu\n",
+                      "TBF enqueues: class@%p rate %u gen %llu "
+                      "token %llu, rule@%p rate %u gen %llu\n",
                       cli, cli->tc_rpc_rate,
                       cli->tc_rule_generation, cli->tc_ntoken,
                       cli->tc_rule, cli->tc_rule->tr_rpc_rate,
@@ -3234,12 +3224,12 @@ static void nrs_tbf_req_del(struct ptlrpc_nrs_policy *policy,
        LASSERT(!list_empty(&nrq->nr_u.tbf.tr_list));
        list_del_init(&nrq->nr_u.tbf.tr_list);
        if (list_empty(&cli->tc_list)) {
-               cfs_binheap_remove(head->th_binheap,
-                                  &cli->tc_node);
+               binheap_remove(head->th_binheap,
+                              &cli->tc_node);
                cli->tc_in_heap = false;
        } else {
-               cfs_binheap_relocate(head->th_binheap,
-                                    &cli->tc_node);
+               binheap_relocate(head->th_binheap,
+                                &cli->tc_node);
        }
 }
 
@@ -3667,7 +3657,7 @@ LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_nrs_tbf_rule);
  */
 static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
 {
-       struct lprocfs_vars nrs_tbf_lprocfs_vars[] = {
+       struct ldebugfs_vars nrs_tbf_lprocfs_vars[] = {
                { .name         = "nrs_tbf_rule",
                  .fops         = &ptlrpc_lprocfs_nrs_tbf_rule_fops,
                  .data = svc },
@@ -3677,8 +3667,9 @@ static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
        if (!svc->srv_debugfs_entry)
                return 0;
 
-       return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_tbf_lprocfs_vars,
-                                NULL);
+       ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_tbf_lprocfs_vars, NULL);
+
+       return 0;
 }
 
 /**
@@ -3709,5 +3700,3 @@ struct ptlrpc_nrs_pol_conf nrs_conf_tbf = {
 /** @} tbf */
 
 /** @} nrs */
-
-#endif /* HAVE_SERVER_SUPPORT */