[DCCP]: Move the calc_X routines to dccp_tfrc_lib

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Arnaldo Carvalho de Melo and committed by
David S. Miller
36729c1a 5cea0ddc

+672 -620
+5 -619
net/dccp/ccids/ccid3.c
··· 39 #include "../dccp.h" 40 #include "lib/packet_history.h" 41 #include "lib/loss_interval.h" 42 #include "ccid3.h" 43 44 /* ··· 113 hctx->ccid3hctx_state = state; 114 } 115 116 - #define CALCX_ARRSIZE 500 117 - 118 - #define CALCX_SPLIT 50000 119 - /* equivalent to 0.05 */ 120 - 121 - static const u32 calcx_lookup[CALCX_ARRSIZE][2] = { 122 - { 37172 , 8172 }, 123 - { 53499 , 11567 }, 124 - { 66664 , 14180 }, 125 - { 78298 , 16388 }, 126 - { 89021 , 18339 }, 127 - { 99147 , 20108 }, 128 - { 108858 , 21738 }, 129 - { 118273 , 23260 }, 130 - { 127474 , 24693 }, 131 - { 136520 , 26052 }, 132 - { 145456 , 27348 }, 133 - { 154316 , 28589 }, 134 - { 163130 , 29783 }, 135 - { 171919 , 30935 }, 136 - { 180704 , 32049 }, 137 - { 189502 , 33130 }, 138 - { 198328 , 34180 }, 139 - { 207194 , 35202 }, 140 - { 216114 , 36198 }, 141 - { 225097 , 37172 }, 142 - { 234153 , 38123 }, 143 - { 243294 , 39055 }, 144 - { 252527 , 39968 }, 145 - { 261861 , 40864 }, 146 - { 271305 , 41743 }, 147 - { 280866 , 42607 }, 148 - { 290553 , 43457 }, 149 - { 300372 , 44293 }, 150 - { 310333 , 45117 }, 151 - { 320441 , 45929 }, 152 - { 330705 , 46729 }, 153 - { 341131 , 47518 }, 154 - { 351728 , 48297 }, 155 - { 362501 , 49066 }, 156 - { 373460 , 49826 }, 157 - { 384609 , 50577 }, 158 - { 395958 , 51320 }, 159 - { 407513 , 52054 }, 160 - { 419281 , 52780 }, 161 - { 431270 , 53499 }, 162 - { 443487 , 54211 }, 163 - { 455940 , 54916 }, 164 - { 468635 , 55614 }, 165 - { 481581 , 56306 }, 166 - { 494785 , 56991 }, 167 - { 508254 , 57671 }, 168 - { 521996 , 58345 }, 169 - { 536019 , 59014 }, 170 - { 550331 , 59677 }, 171 - { 564939 , 60335 }, 172 - { 579851 , 60988 }, 173 - { 595075 , 61636 }, 174 - { 610619 , 62279 }, 175 - { 626491 , 62918 }, 176 - { 642700 , 63553 }, 177 - { 659253 , 64183 }, 178 - { 676158 , 64809 }, 179 - { 693424 , 65431 }, 180 - { 711060 , 66050 }, 181 - { 729073 , 66664 }, 182 - { 747472 , 67275 }, 183 - { 766266 , 67882 }, 184 - { 785464 , 68486 }, 185 - { 805073 , 69087 }, 186 - { 825103 , 69684 }, 187 - { 845562 , 70278 }, 188 - { 866460 , 70868 }, 189 - { 887805 , 71456 }, 190 - { 909606 , 72041 }, 191 - { 931873 , 72623 }, 192 - { 954614 , 73202 }, 193 - { 977839 , 73778 }, 194 - { 1001557 , 74352 }, 195 - { 1025777 , 74923 }, 196 - { 1050508 , 75492 }, 197 - { 1075761 , 76058 }, 198 - { 1101544 , 76621 }, 199 - { 1127867 , 77183 }, 200 - { 1154739 , 77741 }, 201 - { 1182172 , 78298 }, 202 - { 1210173 , 78852 }, 203 - { 1238753 , 79405 }, 204 - { 1267922 , 79955 }, 205 - { 1297689 , 80503 }, 206 - { 1328066 , 81049 }, 207 - { 1359060 , 81593 }, 208 - { 1390684 , 82135 }, 209 - { 1422947 , 82675 }, 210 - { 1455859 , 83213 }, 211 - { 1489430 , 83750 }, 212 - { 1523671 , 84284 }, 213 - { 1558593 , 84817 }, 214 - { 1594205 , 85348 }, 215 - { 1630518 , 85878 }, 216 - { 1667543 , 86406 }, 217 - { 1705290 , 86932 }, 218 - { 1743770 , 87457 }, 219 - { 1782994 , 87980 }, 220 - { 1822973 , 88501 }, 221 - { 1863717 , 89021 }, 222 - { 1905237 , 89540 }, 223 - { 1947545 , 90057 }, 224 - { 1990650 , 90573 }, 225 - { 2034566 , 91087 }, 226 - { 2079301 , 91600 }, 227 - { 2124869 , 92111 }, 228 - { 2171279 , 92622 }, 229 - { 2218543 , 93131 }, 230 - { 2266673 , 93639 }, 231 - { 2315680 , 94145 }, 232 - { 2365575 , 94650 }, 233 - { 2416371 , 95154 }, 234 - { 2468077 , 95657 }, 235 - { 2520707 , 96159 }, 236 - { 2574271 , 96660 }, 237 - { 2628782 , 97159 }, 238 - { 2684250 , 97658 }, 239 - { 2740689 , 98155 }, 240 - { 2798110 , 98651 }, 241 - { 2856524 , 99147 }, 242 - { 2915944 , 99641 }, 243 - { 2976382 , 100134 }, 244 - { 3037850 , 100626 }, 245 - { 3100360 , 101117 }, 246 - { 3163924 , 101608 }, 247 - { 3228554 , 102097 }, 248 - { 3294263 , 102586 }, 249 - { 3361063 , 103073 }, 250 - { 3428966 , 103560 }, 251 - { 3497984 , 104045 }, 252 - { 3568131 , 104530 }, 253 - { 3639419 , 105014 }, 254 - { 3711860 , 105498 }, 255 - { 3785467 , 105980 }, 256 - { 3860253 , 106462 }, 257 - { 3936229 , 106942 }, 258 - { 4013410 , 107422 }, 259 - { 4091808 , 107902 }, 260 - { 4171435 , 108380 }, 261 - { 4252306 , 108858 }, 262 - { 4334431 , 109335 }, 263 - { 4417825 , 109811 }, 264 - { 4502501 , 110287 }, 265 - { 4588472 , 110762 }, 266 - { 4675750 , 111236 }, 267 - { 4764349 , 111709 }, 268 - { 4854283 , 112182 }, 269 - { 4945564 , 112654 }, 270 - { 5038206 , 113126 }, 271 - { 5132223 , 113597 }, 272 - { 5227627 , 114067 }, 273 - { 5324432 , 114537 }, 274 - { 5422652 , 115006 }, 275 - { 5522299 , 115474 }, 276 - { 5623389 , 115942 }, 277 - { 5725934 , 116409 }, 278 - { 5829948 , 116876 }, 279 - { 5935446 , 117342 }, 280 - { 6042439 , 117808 }, 281 - { 6150943 , 118273 }, 282 - { 6260972 , 118738 }, 283 - { 6372538 , 119202 }, 284 - { 6485657 , 119665 }, 285 - { 6600342 , 120128 }, 286 - { 6716607 , 120591 }, 287 - { 6834467 , 121053 }, 288 - { 6953935 , 121514 }, 289 - { 7075025 , 121976 }, 290 - { 7197752 , 122436 }, 291 - { 7322131 , 122896 }, 292 - { 7448175 , 123356 }, 293 - { 7575898 , 123815 }, 294 - { 7705316 , 124274 }, 295 - { 7836442 , 124733 }, 296 - { 7969291 , 125191 }, 297 - { 8103877 , 125648 }, 298 - { 8240216 , 126105 }, 299 - { 8378321 , 126562 }, 300 - { 8518208 , 127018 }, 301 - { 8659890 , 127474 }, 302 - { 8803384 , 127930 }, 303 - { 8948702 , 128385 }, 304 - { 9095861 , 128840 }, 305 - { 9244875 , 129294 }, 306 - { 9395760 , 129748 }, 307 - { 9548529 , 130202 }, 308 - { 9703198 , 130655 }, 309 - { 9859782 , 131108 }, 310 - { 10018296 , 131561 }, 311 - { 10178755 , 132014 }, 312 - { 10341174 , 132466 }, 313 - { 10505569 , 132917 }, 314 - { 10671954 , 133369 }, 315 - { 10840345 , 133820 }, 316 - { 11010757 , 134271 }, 317 - { 11183206 , 134721 }, 318 - { 11357706 , 135171 }, 319 - { 11534274 , 135621 }, 320 - { 11712924 , 136071 }, 321 - { 11893673 , 136520 }, 322 - { 12076536 , 136969 }, 323 - { 12261527 , 137418 }, 324 - { 12448664 , 137867 }, 325 - { 12637961 , 138315 }, 326 - { 12829435 , 138763 }, 327 - { 13023101 , 139211 }, 328 - { 13218974 , 139658 }, 329 - { 13417071 , 140106 }, 330 - { 13617407 , 140553 }, 331 - { 13819999 , 140999 }, 332 - { 14024862 , 141446 }, 333 - { 14232012 , 141892 }, 334 - { 14441465 , 142339 }, 335 - { 14653238 , 142785 }, 336 - { 14867346 , 143230 }, 337 - { 15083805 , 143676 }, 338 - { 15302632 , 144121 }, 339 - { 15523842 , 144566 }, 340 - { 15747453 , 145011 }, 341 - { 15973479 , 145456 }, 342 - { 16201939 , 145900 }, 343 - { 16432847 , 146345 }, 344 - { 16666221 , 146789 }, 345 - { 16902076 , 147233 }, 346 - { 17140429 , 147677 }, 347 - { 17381297 , 148121 }, 348 - { 17624696 , 148564 }, 349 - { 17870643 , 149007 }, 350 - { 18119154 , 149451 }, 351 - { 18370247 , 149894 }, 352 - { 18623936 , 150336 }, 353 - { 18880241 , 150779 }, 354 - { 19139176 , 151222 }, 355 - { 19400759 , 151664 }, 356 - { 19665007 , 152107 }, 357 - { 19931936 , 152549 }, 358 - { 20201564 , 152991 }, 359 - { 20473907 , 153433 }, 360 - { 20748982 , 153875 }, 361 - { 21026807 , 154316 }, 362 - { 21307399 , 154758 }, 363 - { 21590773 , 155199 }, 364 - { 21876949 , 155641 }, 365 - { 22165941 , 156082 }, 366 - { 22457769 , 156523 }, 367 - { 22752449 , 156964 }, 368 - { 23049999 , 157405 }, 369 - { 23350435 , 157846 }, 370 - { 23653774 , 158287 }, 371 - { 23960036 , 158727 }, 372 - { 24269236 , 159168 }, 373 - { 24581392 , 159608 }, 374 - { 24896521 , 160049 }, 375 - { 25214642 , 160489 }, 376 - { 25535772 , 160929 }, 377 - { 25859927 , 161370 }, 378 - { 26187127 , 161810 }, 379 - { 26517388 , 162250 }, 380 - { 26850728 , 162690 }, 381 - { 27187165 , 163130 }, 382 - { 27526716 , 163569 }, 383 - { 27869400 , 164009 }, 384 - { 28215234 , 164449 }, 385 - { 28564236 , 164889 }, 386 - { 28916423 , 165328 }, 387 - { 29271815 , 165768 }, 388 - { 29630428 , 166208 }, 389 - { 29992281 , 166647 }, 390 - { 30357392 , 167087 }, 391 - { 30725779 , 167526 }, 392 - { 31097459 , 167965 }, 393 - { 31472452 , 168405 }, 394 - { 31850774 , 168844 }, 395 - { 32232445 , 169283 }, 396 - { 32617482 , 169723 }, 397 - { 33005904 , 170162 }, 398 - { 33397730 , 170601 }, 399 - { 33792976 , 171041 }, 400 - { 34191663 , 171480 }, 401 - { 34593807 , 171919 }, 402 - { 34999428 , 172358 }, 403 - { 35408544 , 172797 }, 404 - { 35821174 , 173237 }, 405 - { 36237335 , 173676 }, 406 - { 36657047 , 174115 }, 407 - { 37080329 , 174554 }, 408 - { 37507197 , 174993 }, 409 - { 37937673 , 175433 }, 410 - { 38371773 , 175872 }, 411 - { 38809517 , 176311 }, 412 - { 39250924 , 176750 }, 413 - { 39696012 , 177190 }, 414 - { 40144800 , 177629 }, 415 - { 40597308 , 178068 }, 416 - { 41053553 , 178507 }, 417 - { 41513554 , 178947 }, 418 - { 41977332 , 179386 }, 419 - { 42444904 , 179825 }, 420 - { 42916290 , 180265 }, 421 - { 43391509 , 180704 }, 422 - { 43870579 , 181144 }, 423 - { 44353520 , 181583 }, 424 - { 44840352 , 182023 }, 425 - { 45331092 , 182462 }, 426 - { 45825761 , 182902 }, 427 - { 46324378 , 183342 }, 428 - { 46826961 , 183781 }, 429 - { 47333531 , 184221 }, 430 - { 47844106 , 184661 }, 431 - { 48358706 , 185101 }, 432 - { 48877350 , 185541 }, 433 - { 49400058 , 185981 }, 434 - { 49926849 , 186421 }, 435 - { 50457743 , 186861 }, 436 - { 50992759 , 187301 }, 437 - { 51531916 , 187741 }, 438 - { 52075235 , 188181 }, 439 - { 52622735 , 188622 }, 440 - { 53174435 , 189062 }, 441 - { 53730355 , 189502 }, 442 - { 54290515 , 189943 }, 443 - { 54854935 , 190383 }, 444 - { 55423634 , 190824 }, 445 - { 55996633 , 191265 }, 446 - { 56573950 , 191706 }, 447 - { 57155606 , 192146 }, 448 - { 57741621 , 192587 }, 449 - { 58332014 , 193028 }, 450 - { 58926806 , 193470 }, 451 - { 59526017 , 193911 }, 452 - { 60129666 , 194352 }, 453 - { 60737774 , 194793 }, 454 - { 61350361 , 195235 }, 455 - { 61967446 , 195677 }, 456 - { 62589050 , 196118 }, 457 - { 63215194 , 196560 }, 458 - { 63845897 , 197002 }, 459 - { 64481179 , 197444 }, 460 - { 65121061 , 197886 }, 461 - { 65765563 , 198328 }, 462 - { 66414705 , 198770 }, 463 - { 67068508 , 199213 }, 464 - { 67726992 , 199655 }, 465 - { 68390177 , 200098 }, 466 - { 69058085 , 200540 }, 467 - { 69730735 , 200983 }, 468 - { 70408147 , 201426 }, 469 - { 71090343 , 201869 }, 470 - { 71777343 , 202312 }, 471 - { 72469168 , 202755 }, 472 - { 73165837 , 203199 }, 473 - { 73867373 , 203642 }, 474 - { 74573795 , 204086 }, 475 - { 75285124 , 204529 }, 476 - { 76001380 , 204973 }, 477 - { 76722586 , 205417 }, 478 - { 77448761 , 205861 }, 479 - { 78179926 , 206306 }, 480 - { 78916102 , 206750 }, 481 - { 79657310 , 207194 }, 482 - { 80403571 , 207639 }, 483 - { 81154906 , 208084 }, 484 - { 81911335 , 208529 }, 485 - { 82672880 , 208974 }, 486 - { 83439562 , 209419 }, 487 - { 84211402 , 209864 }, 488 - { 84988421 , 210309 }, 489 - { 85770640 , 210755 }, 490 - { 86558080 , 211201 }, 491 - { 87350762 , 211647 }, 492 - { 88148708 , 212093 }, 493 - { 88951938 , 212539 }, 494 - { 89760475 , 212985 }, 495 - { 90574339 , 213432 }, 496 - { 91393551 , 213878 }, 497 - { 92218133 , 214325 }, 498 - { 93048107 , 214772 }, 499 - { 93883493 , 215219 }, 500 - { 94724314 , 215666 }, 501 - { 95570590 , 216114 }, 502 - { 96422343 , 216561 }, 503 - { 97279594 , 217009 }, 504 - { 98142366 , 217457 }, 505 - { 99010679 , 217905 }, 506 - { 99884556 , 218353 }, 507 - { 100764018 , 218801 }, 508 - { 101649086 , 219250 }, 509 - { 102539782 , 219698 }, 510 - { 103436128 , 220147 }, 511 - { 104338146 , 220596 }, 512 - { 105245857 , 221046 }, 513 - { 106159284 , 221495 }, 514 - { 107078448 , 221945 }, 515 - { 108003370 , 222394 }, 516 - { 108934074 , 222844 }, 517 - { 109870580 , 223294 }, 518 - { 110812910 , 223745 }, 519 - { 111761087 , 224195 }, 520 - { 112715133 , 224646 }, 521 - { 113675069 , 225097 }, 522 - { 114640918 , 225548 }, 523 - { 115612702 , 225999 }, 524 - { 116590442 , 226450 }, 525 - { 117574162 , 226902 }, 526 - { 118563882 , 227353 }, 527 - { 119559626 , 227805 }, 528 - { 120561415 , 228258 }, 529 - { 121569272 , 228710 }, 530 - { 122583219 , 229162 }, 531 - { 123603278 , 229615 }, 532 - { 124629471 , 230068 }, 533 - { 125661822 , 230521 }, 534 - { 126700352 , 230974 }, 535 - { 127745083 , 231428 }, 536 - { 128796039 , 231882 }, 537 - { 129853241 , 232336 }, 538 - { 130916713 , 232790 }, 539 - { 131986475 , 233244 }, 540 - { 133062553 , 233699 }, 541 - { 134144966 , 234153 }, 542 - { 135233739 , 234608 }, 543 - { 136328894 , 235064 }, 544 - { 137430453 , 235519 }, 545 - { 138538440 , 235975 }, 546 - { 139652876 , 236430 }, 547 - { 140773786 , 236886 }, 548 - { 141901190 , 237343 }, 549 - { 143035113 , 237799 }, 550 - { 144175576 , 238256 }, 551 - { 145322604 , 238713 }, 552 - { 146476218 , 239170 }, 553 - { 147636442 , 239627 }, 554 - { 148803298 , 240085 }, 555 - { 149976809 , 240542 }, 556 - { 151156999 , 241000 }, 557 - { 152343890 , 241459 }, 558 - { 153537506 , 241917 }, 559 - { 154737869 , 242376 }, 560 - { 155945002 , 242835 }, 561 - { 157158929 , 243294 }, 562 - { 158379673 , 243753 }, 563 - { 159607257 , 244213 }, 564 - { 160841704 , 244673 }, 565 - { 162083037 , 245133 }, 566 - { 163331279 , 245593 }, 567 - { 164586455 , 246054 }, 568 - { 165848586 , 246514 }, 569 - { 167117696 , 246975 }, 570 - { 168393810 , 247437 }, 571 - { 169676949 , 247898 }, 572 - { 170967138 , 248360 }, 573 - { 172264399 , 248822 }, 574 - { 173568757 , 249284 }, 575 - { 174880235 , 249747 }, 576 - { 176198856 , 250209 }, 577 - { 177524643 , 250672 }, 578 - { 178857621 , 251136 }, 579 - { 180197813 , 251599 }, 580 - { 181545242 , 252063 }, 581 - { 182899933 , 252527 }, 582 - { 184261908 , 252991 }, 583 - { 185631191 , 253456 }, 584 - { 187007807 , 253920 }, 585 - { 188391778 , 254385 }, 586 - { 189783129 , 254851 }, 587 - { 191181884 , 255316 }, 588 - { 192588065 , 255782 }, 589 - { 194001698 , 256248 }, 590 - { 195422805 , 256714 }, 591 - { 196851411 , 257181 }, 592 - { 198287540 , 257648 }, 593 - { 199731215 , 258115 }, 594 - { 201182461 , 258582 }, 595 - { 202641302 , 259050 }, 596 - { 204107760 , 259518 }, 597 - { 205581862 , 259986 }, 598 - { 207063630 , 260454 }, 599 - { 208553088 , 260923 }, 600 - { 210050262 , 261392 }, 601 - { 211555174 , 261861 }, 602 - { 213067849 , 262331 }, 603 - { 214588312 , 262800 }, 604 - { 216116586 , 263270 }, 605 - { 217652696 , 263741 }, 606 - { 219196666 , 264211 }, 607 - { 220748520 , 264682 }, 608 - { 222308282 , 265153 }, 609 - { 223875978 , 265625 }, 610 - { 225451630 , 266097 }, 611 - { 227035265 , 266569 }, 612 - { 228626905 , 267041 }, 613 - { 230226576 , 267514 }, 614 - { 231834302 , 267986 }, 615 - { 233450107 , 268460 }, 616 - { 235074016 , 268933 }, 617 - { 236706054 , 269407 }, 618 - { 238346244 , 269881 }, 619 - { 239994613 , 270355 }, 620 - { 241651183 , 270830 }, 621 - { 243315981 , 271305 } 622 - }; 623 - 624 - /* Calculate the send rate as per section 3.1 of RFC3448 625 - 626 - Returns send rate in bytes per second 627 - 628 - Integer maths and lookups are used as not allowed floating point in kernel 629 - 630 - The function for Xcalc as per section 3.1 of RFC3448 is: 631 - 632 - X = s 633 - ------------------------------------------------------------- 634 - R*sqrt(2*b*p/3) + (t_RTO * (3*sqrt(3*b*p/8) * p * (1+32*p^2))) 635 - 636 - where 637 - X is the trasmit rate in bytes/second 638 - s is the packet size in bytes 639 - R is the round trip time in seconds 640 - p is the loss event rate, between 0 and 1.0, of the number of loss events 641 - as a fraction of the number of packets transmitted 642 - t_RTO is the TCP retransmission timeout value in seconds 643 - b is the number of packets acknowledged by a single TCP acknowledgement 644 - 645 - we can assume that b = 1 and t_RTO is 4 * R. With this the equation becomes: 646 - 647 - X = s 648 - ----------------------------------------------------------------------- 649 - R * sqrt(2 * p / 3) + (12 * R * (sqrt(3 * p / 8) * p * (1 + 32 * p^2))) 650 - 651 - 652 - which we can break down into: 653 - 654 - X = s 655 - -------- 656 - R * f(p) 657 - 658 - where f(p) = sqrt(2 * p / 3) + (12 * sqrt(3 * p / 8) * p * (1 + 32 * p * p)) 659 - 660 - Function parameters: 661 - s - bytes 662 - R - RTT in usecs 663 - p - loss rate (decimal fraction multiplied by 1,000,000) 664 - 665 - Returns Xcalc in bytes per second 666 - 667 - DON'T alter this code unless you run test cases against it as the code 668 - has been manipulated to stop underflow/overlow. 669 - 670 - */ 671 - static u32 ccid3_calc_x(u16 s, u32 R, u32 p) 672 - { 673 - int index; 674 - u32 f; 675 - u64 tmp1, tmp2; 676 - 677 - if (p < CALCX_SPLIT) 678 - index = (p / (CALCX_SPLIT / CALCX_ARRSIZE)) - 1; 679 - else 680 - index = (p / (1000000 / CALCX_ARRSIZE)) - 1; 681 - 682 - if (index < 0) 683 - /* p should be 0 unless there is a bug in my code */ 684 - index = 0; 685 - 686 - if (R == 0) 687 - R = 1; /* RTT can't be zero or else divide by zero */ 688 - 689 - BUG_ON(index >= CALCX_ARRSIZE); 690 - 691 - if (p >= CALCX_SPLIT) 692 - f = calcx_lookup[index][0]; 693 - else 694 - f = calcx_lookup[index][1]; 695 - 696 - tmp1 = ((u64)s * 100000000); 697 - tmp2 = ((u64)R * (u64)f); 698 - do_div(tmp2,10000); 699 - do_div(tmp1,tmp2); 700 - /* don't alter above math unless you test due to overflow on 32 bit */ 701 - 702 - return (u32)tmp1; 703 - } 704 - 705 /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ 706 static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx) 707 { ··· 149 150 /* To avoid large error in calcX */ 151 if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { 152 - hctx->ccid3hctx_x_calc = ccid3_calc_x(hctx->ccid3hctx_s, 153 - hctx->ccid3hctx_rtt, 154 - hctx->ccid3hctx_p); 155 hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, 156 2 * hctx->ccid3hctx_x_recv), 157 (hctx->ccid3hctx_s / ··· 945 &x_recv, sizeof(x_recv)); 946 } 947 948 - /* 949 - * args: fvalue - function value to match 950 - * returns: p closest to that value 951 - * 952 - * both fvalue and p are multiplied by 1,000,000 to use ints 953 - */ 954 - static u32 calcx_reverse_lookup(u32 fvalue) { 955 - int ctr = 0; 956 - int small; 957 - 958 - if (fvalue < calcx_lookup[0][1]) 959 - return 0; 960 - if (fvalue <= calcx_lookup[CALCX_ARRSIZE-1][1]) 961 - small = 1; 962 - else if (fvalue > calcx_lookup[CALCX_ARRSIZE-1][0]) 963 - return 1000000; 964 - else 965 - small = 0; 966 - while (fvalue > calcx_lookup[ctr][small]) 967 - ctr++; 968 - if (small) 969 - return (CALCX_SPLIT * ctr / CALCX_ARRSIZE); 970 - else 971 - return (1000000 * ctr / CALCX_ARRSIZE) ; 972 - } 973 - 974 /* calculate first loss interval 975 * 976 * returns estimated loss interval in usecs */ ··· 1013 tmp2 = (u32)tmp1; 1014 fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; 1015 /* do not alter order above or you will get overflow on 32 bit */ 1016 - p = calcx_reverse_lookup(fval); 1017 ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied " 1018 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); 1019
··· 39 #include "../dccp.h" 40 #include "lib/packet_history.h" 41 #include "lib/loss_interval.h" 42 + #include "lib/tfrc.h" 43 #include "ccid3.h" 44 45 /* ··· 112 hctx->ccid3hctx_state = state; 113 } 114 115 /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ 116 static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx) 117 { ··· 737 738 /* To avoid large error in calcX */ 739 if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { 740 + hctx->ccid3hctx_x_calc = tfrc_calc_x(hctx->ccid3hctx_s, 741 + hctx->ccid3hctx_rtt, 742 + hctx->ccid3hctx_p); 743 hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, 744 2 * hctx->ccid3hctx_x_recv), 745 (hctx->ccid3hctx_s / ··· 1533 &x_recv, sizeof(x_recv)); 1534 } 1535 1536 /* calculate first loss interval 1537 * 1538 * returns estimated loss interval in usecs */ ··· 1627 tmp2 = (u32)tmp1; 1628 fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; 1629 /* do not alter order above or you will get overflow on 32 bit */ 1630 + p = tfrc_calc_x_reverse_lookup(fval); 1631 ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied " 1632 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); 1633
+1 -1
net/dccp/ccids/lib/Makefile
··· 1 obj-$(CONFIG_IP_DCCP_TFRC_LIB) += dccp_tfrc_lib.o 2 3 - dccp_tfrc_lib-y := loss_interval.o packet_history.o
··· 1 obj-$(CONFIG_IP_DCCP_TFRC_LIB) += dccp_tfrc_lib.o 2 3 + dccp_tfrc_lib-y := loss_interval.o packet_history.o tfrc_equation.o
+22
net/dccp/ccids/lib/tfrc.h
···
··· 1 + #ifndef _TFRC_H_ 2 + #define _TFRC_H_ 3 + /* 4 + * net/dccp/ccids/lib/tfrc.h 5 + * 6 + * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. 7 + * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz> 8 + * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 9 + * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + */ 16 + 17 + #include <linux/types.h> 18 + 19 + extern u32 tfrc_calc_x(u16 s, u32 R, u32 p); 20 + extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue); 21 + 22 + #endif /* _TFRC_H_ */
+644
net/dccp/ccids/lib/tfrc_equation.c
···
··· 1 + /* 2 + * net/dccp/ccids/lib/tfrc_equation.c 3 + * 4 + * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. 5 + * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz> 6 + * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 7 + * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; either version 2 of the License, or 12 + * (at your option) any later version. 13 + */ 14 + 15 + #include <linux/config.h> 16 + #include <linux/module.h> 17 + 18 + #include <asm/bug.h> 19 + #include <asm/div64.h> 20 + 21 + #include "tfrc.h" 22 + 23 + #define TFRC_CALC_X_ARRSIZE 500 24 + 25 + #define TFRC_CALC_X_SPLIT 50000 26 + /* equivalent to 0.05 */ 27 + 28 + static const u32 tfrc_calc_x_lookup[TFRC_CALC_X_ARRSIZE][2] = { 29 + { 37172, 8172 }, 30 + { 53499, 11567 }, 31 + { 66664, 14180 }, 32 + { 78298, 16388 }, 33 + { 89021, 18339 }, 34 + { 99147, 20108 }, 35 + { 108858, 21738 }, 36 + { 118273, 23260 }, 37 + { 127474, 24693 }, 38 + { 136520, 26052 }, 39 + { 145456, 27348 }, 40 + { 154316, 28589 }, 41 + { 163130, 29783 }, 42 + { 171919, 30935 }, 43 + { 180704, 32049 }, 44 + { 189502, 33130 }, 45 + { 198328, 34180 }, 46 + { 207194, 35202 }, 47 + { 216114, 36198 }, 48 + { 225097, 37172 }, 49 + { 234153, 38123 }, 50 + { 243294, 39055 }, 51 + { 252527, 39968 }, 52 + { 261861, 40864 }, 53 + { 271305, 41743 }, 54 + { 280866, 42607 }, 55 + { 290553, 43457 }, 56 + { 300372, 44293 }, 57 + { 310333, 45117 }, 58 + { 320441, 45929 }, 59 + { 330705, 46729 }, 60 + { 341131, 47518 }, 61 + { 351728, 48297 }, 62 + { 362501, 49066 }, 63 + { 373460, 49826 }, 64 + { 384609, 50577 }, 65 + { 395958, 51320 }, 66 + { 407513, 52054 }, 67 + { 419281, 52780 }, 68 + { 431270, 53499 }, 69 + { 443487, 54211 }, 70 + { 455940, 54916 }, 71 + { 468635, 55614 }, 72 + { 481581, 56306 }, 73 + { 494785, 56991 }, 74 + { 508254, 57671 }, 75 + { 521996, 58345 }, 76 + { 536019, 59014 }, 77 + { 550331, 59677 }, 78 + { 564939, 60335 }, 79 + { 579851, 60988 }, 80 + { 595075, 61636 }, 81 + { 610619, 62279 }, 82 + { 626491, 62918 }, 83 + { 642700, 63553 }, 84 + { 659253, 64183 }, 85 + { 676158, 64809 }, 86 + { 693424, 65431 }, 87 + { 711060, 66050 }, 88 + { 729073, 66664 }, 89 + { 747472, 67275 }, 90 + { 766266, 67882 }, 91 + { 785464, 68486 }, 92 + { 805073, 69087 }, 93 + { 825103, 69684 }, 94 + { 845562, 70278 }, 95 + { 866460, 70868 }, 96 + { 887805, 71456 }, 97 + { 909606, 72041 }, 98 + { 931873, 72623 }, 99 + { 954614, 73202 }, 100 + { 977839, 73778 }, 101 + { 1001557, 74352 }, 102 + { 1025777, 74923 }, 103 + { 1050508, 75492 }, 104 + { 1075761, 76058 }, 105 + { 1101544, 76621 }, 106 + { 1127867, 77183 }, 107 + { 1154739, 77741 }, 108 + { 1182172, 78298 }, 109 + { 1210173, 78852 }, 110 + { 1238753, 79405 }, 111 + { 1267922, 79955 }, 112 + { 1297689, 80503 }, 113 + { 1328066, 81049 }, 114 + { 1359060, 81593 }, 115 + { 1390684, 82135 }, 116 + { 1422947, 82675 }, 117 + { 1455859, 83213 }, 118 + { 1489430, 83750 }, 119 + { 1523671, 84284 }, 120 + { 1558593, 84817 }, 121 + { 1594205, 85348 }, 122 + { 1630518, 85878 }, 123 + { 1667543, 86406 }, 124 + { 1705290, 86932 }, 125 + { 1743770, 87457 }, 126 + { 1782994, 87980 }, 127 + { 1822973, 88501 }, 128 + { 1863717, 89021 }, 129 + { 1905237, 89540 }, 130 + { 1947545, 90057 }, 131 + { 1990650, 90573 }, 132 + { 2034566, 91087 }, 133 + { 2079301, 91600 }, 134 + { 2124869, 92111 }, 135 + { 2171279, 92622 }, 136 + { 2218543, 93131 }, 137 + { 2266673, 93639 }, 138 + { 2315680, 94145 }, 139 + { 2365575, 94650 }, 140 + { 2416371, 95154 }, 141 + { 2468077, 95657 }, 142 + { 2520707, 96159 }, 143 + { 2574271, 96660 }, 144 + { 2628782, 97159 }, 145 + { 2684250, 97658 }, 146 + { 2740689, 98155 }, 147 + { 2798110, 98651 }, 148 + { 2856524, 99147 }, 149 + { 2915944, 99641 }, 150 + { 2976382, 100134 }, 151 + { 3037850, 100626 }, 152 + { 3100360, 101117 }, 153 + { 3163924, 101608 }, 154 + { 3228554, 102097 }, 155 + { 3294263, 102586 }, 156 + { 3361063, 103073 }, 157 + { 3428966, 103560 }, 158 + { 3497984, 104045 }, 159 + { 3568131, 104530 }, 160 + { 3639419, 105014 }, 161 + { 3711860, 105498 }, 162 + { 3785467, 105980 }, 163 + { 3860253, 106462 }, 164 + { 3936229, 106942 }, 165 + { 4013410, 107422 }, 166 + { 4091808, 107902 }, 167 + { 4171435, 108380 }, 168 + { 4252306, 108858 }, 169 + { 4334431, 109335 }, 170 + { 4417825, 109811 }, 171 + { 4502501, 110287 }, 172 + { 4588472, 110762 }, 173 + { 4675750, 111236 }, 174 + { 4764349, 111709 }, 175 + { 4854283, 112182 }, 176 + { 4945564, 112654 }, 177 + { 5038206, 113126 }, 178 + { 5132223, 113597 }, 179 + { 5227627, 114067 }, 180 + { 5324432, 114537 }, 181 + { 5422652, 115006 }, 182 + { 5522299, 115474 }, 183 + { 5623389, 115942 }, 184 + { 5725934, 116409 }, 185 + { 5829948, 116876 }, 186 + { 5935446, 117342 }, 187 + { 6042439, 117808 }, 188 + { 6150943, 118273 }, 189 + { 6260972, 118738 }, 190 + { 6372538, 119202 }, 191 + { 6485657, 119665 }, 192 + { 6600342, 120128 }, 193 + { 6716607, 120591 }, 194 + { 6834467, 121053 }, 195 + { 6953935, 121514 }, 196 + { 7075025, 121976 }, 197 + { 7197752, 122436 }, 198 + { 7322131, 122896 }, 199 + { 7448175, 123356 }, 200 + { 7575898, 123815 }, 201 + { 7705316, 124274 }, 202 + { 7836442, 124733 }, 203 + { 7969291, 125191 }, 204 + { 8103877, 125648 }, 205 + { 8240216, 126105 }, 206 + { 8378321, 126562 }, 207 + { 8518208, 127018 }, 208 + { 8659890, 127474 }, 209 + { 8803384, 127930 }, 210 + { 8948702, 128385 }, 211 + { 9095861, 128840 }, 212 + { 9244875, 129294 }, 213 + { 9395760, 129748 }, 214 + { 9548529, 130202 }, 215 + { 9703198, 130655 }, 216 + { 9859782, 131108 }, 217 + { 10018296, 131561 }, 218 + { 10178755, 132014 }, 219 + { 10341174, 132466 }, 220 + { 10505569, 132917 }, 221 + { 10671954, 133369 }, 222 + { 10840345, 133820 }, 223 + { 11010757, 134271 }, 224 + { 11183206, 134721 }, 225 + { 11357706, 135171 }, 226 + { 11534274, 135621 }, 227 + { 11712924, 136071 }, 228 + { 11893673, 136520 }, 229 + { 12076536, 136969 }, 230 + { 12261527, 137418 }, 231 + { 12448664, 137867 }, 232 + { 12637961, 138315 }, 233 + { 12829435, 138763 }, 234 + { 13023101, 139211 }, 235 + { 13218974, 139658 }, 236 + { 13417071, 140106 }, 237 + { 13617407, 140553 }, 238 + { 13819999, 140999 }, 239 + { 14024862, 141446 }, 240 + { 14232012, 141892 }, 241 + { 14441465, 142339 }, 242 + { 14653238, 142785 }, 243 + { 14867346, 143230 }, 244 + { 15083805, 143676 }, 245 + { 15302632, 144121 }, 246 + { 15523842, 144566 }, 247 + { 15747453, 145011 }, 248 + { 15973479, 145456 }, 249 + { 16201939, 145900 }, 250 + { 16432847, 146345 }, 251 + { 16666221, 146789 }, 252 + { 16902076, 147233 }, 253 + { 17140429, 147677 }, 254 + { 17381297, 148121 }, 255 + { 17624696, 148564 }, 256 + { 17870643, 149007 }, 257 + { 18119154, 149451 }, 258 + { 18370247, 149894 }, 259 + { 18623936, 150336 }, 260 + { 18880241, 150779 }, 261 + { 19139176, 151222 }, 262 + { 19400759, 151664 }, 263 + { 19665007, 152107 }, 264 + { 19931936, 152549 }, 265 + { 20201564, 152991 }, 266 + { 20473907, 153433 }, 267 + { 20748982, 153875 }, 268 + { 21026807, 154316 }, 269 + { 21307399, 154758 }, 270 + { 21590773, 155199 }, 271 + { 21876949, 155641 }, 272 + { 22165941, 156082 }, 273 + { 22457769, 156523 }, 274 + { 22752449, 156964 }, 275 + { 23049999, 157405 }, 276 + { 23350435, 157846 }, 277 + { 23653774, 158287 }, 278 + { 23960036, 158727 }, 279 + { 24269236, 159168 }, 280 + { 24581392, 159608 }, 281 + { 24896521, 160049 }, 282 + { 25214642, 160489 }, 283 + { 25535772, 160929 }, 284 + { 25859927, 161370 }, 285 + { 26187127, 161810 }, 286 + { 26517388, 162250 }, 287 + { 26850728, 162690 }, 288 + { 27187165, 163130 }, 289 + { 27526716, 163569 }, 290 + { 27869400, 164009 }, 291 + { 28215234, 164449 }, 292 + { 28564236, 164889 }, 293 + { 28916423, 165328 }, 294 + { 29271815, 165768 }, 295 + { 29630428, 166208 }, 296 + { 29992281, 166647 }, 297 + { 30357392, 167087 }, 298 + { 30725779, 167526 }, 299 + { 31097459, 167965 }, 300 + { 31472452, 168405 }, 301 + { 31850774, 168844 }, 302 + { 32232445, 169283 }, 303 + { 32617482, 169723 }, 304 + { 33005904, 170162 }, 305 + { 33397730, 170601 }, 306 + { 33792976, 171041 }, 307 + { 34191663, 171480 }, 308 + { 34593807, 171919 }, 309 + { 34999428, 172358 }, 310 + { 35408544, 172797 }, 311 + { 35821174, 173237 }, 312 + { 36237335, 173676 }, 313 + { 36657047, 174115 }, 314 + { 37080329, 174554 }, 315 + { 37507197, 174993 }, 316 + { 37937673, 175433 }, 317 + { 38371773, 175872 }, 318 + { 38809517, 176311 }, 319 + { 39250924, 176750 }, 320 + { 39696012, 177190 }, 321 + { 40144800, 177629 }, 322 + { 40597308, 178068 }, 323 + { 41053553, 178507 }, 324 + { 41513554, 178947 }, 325 + { 41977332, 179386 }, 326 + { 42444904, 179825 }, 327 + { 42916290, 180265 }, 328 + { 43391509, 180704 }, 329 + { 43870579, 181144 }, 330 + { 44353520, 181583 }, 331 + { 44840352, 182023 }, 332 + { 45331092, 182462 }, 333 + { 45825761, 182902 }, 334 + { 46324378, 183342 }, 335 + { 46826961, 183781 }, 336 + { 47333531, 184221 }, 337 + { 47844106, 184661 }, 338 + { 48358706, 185101 }, 339 + { 48877350, 185541 }, 340 + { 49400058, 185981 }, 341 + { 49926849, 186421 }, 342 + { 50457743, 186861 }, 343 + { 50992759, 187301 }, 344 + { 51531916, 187741 }, 345 + { 52075235, 188181 }, 346 + { 52622735, 188622 }, 347 + { 53174435, 189062 }, 348 + { 53730355, 189502 }, 349 + { 54290515, 189943 }, 350 + { 54854935, 190383 }, 351 + { 55423634, 190824 }, 352 + { 55996633, 191265 }, 353 + { 56573950, 191706 }, 354 + { 57155606, 192146 }, 355 + { 57741621, 192587 }, 356 + { 58332014, 193028 }, 357 + { 58926806, 193470 }, 358 + { 59526017, 193911 }, 359 + { 60129666, 194352 }, 360 + { 60737774, 194793 }, 361 + { 61350361, 195235 }, 362 + { 61967446, 195677 }, 363 + { 62589050, 196118 }, 364 + { 63215194, 196560 }, 365 + { 63845897, 197002 }, 366 + { 64481179, 197444 }, 367 + { 65121061, 197886 }, 368 + { 65765563, 198328 }, 369 + { 66414705, 198770 }, 370 + { 67068508, 199213 }, 371 + { 67726992, 199655 }, 372 + { 68390177, 200098 }, 373 + { 69058085, 200540 }, 374 + { 69730735, 200983 }, 375 + { 70408147, 201426 }, 376 + { 71090343, 201869 }, 377 + { 71777343, 202312 }, 378 + { 72469168, 202755 }, 379 + { 73165837, 203199 }, 380 + { 73867373, 203642 }, 381 + { 74573795, 204086 }, 382 + { 75285124, 204529 }, 383 + { 76001380, 204973 }, 384 + { 76722586, 205417 }, 385 + { 77448761, 205861 }, 386 + { 78179926, 206306 }, 387 + { 78916102, 206750 }, 388 + { 79657310, 207194 }, 389 + { 80403571, 207639 }, 390 + { 81154906, 208084 }, 391 + { 81911335, 208529 }, 392 + { 82672880, 208974 }, 393 + { 83439562, 209419 }, 394 + { 84211402, 209864 }, 395 + { 84988421, 210309 }, 396 + { 85770640, 210755 }, 397 + { 86558080, 211201 }, 398 + { 87350762, 211647 }, 399 + { 88148708, 212093 }, 400 + { 88951938, 212539 }, 401 + { 89760475, 212985 }, 402 + { 90574339, 213432 }, 403 + { 91393551, 213878 }, 404 + { 92218133, 214325 }, 405 + { 93048107, 214772 }, 406 + { 93883493, 215219 }, 407 + { 94724314, 215666 }, 408 + { 95570590, 216114 }, 409 + { 96422343, 216561 }, 410 + { 97279594, 217009 }, 411 + { 98142366, 217457 }, 412 + { 99010679, 217905 }, 413 + { 99884556, 218353 }, 414 + { 100764018, 218801 }, 415 + { 101649086, 219250 }, 416 + { 102539782, 219698 }, 417 + { 103436128, 220147 }, 418 + { 104338146, 220596 }, 419 + { 105245857, 221046 }, 420 + { 106159284, 221495 }, 421 + { 107078448, 221945 }, 422 + { 108003370, 222394 }, 423 + { 108934074, 222844 }, 424 + { 109870580, 223294 }, 425 + { 110812910, 223745 }, 426 + { 111761087, 224195 }, 427 + { 112715133, 224646 }, 428 + { 113675069, 225097 }, 429 + { 114640918, 225548 }, 430 + { 115612702, 225999 }, 431 + { 116590442, 226450 }, 432 + { 117574162, 226902 }, 433 + { 118563882, 227353 }, 434 + { 119559626, 227805 }, 435 + { 120561415, 228258 }, 436 + { 121569272, 228710 }, 437 + { 122583219, 229162 }, 438 + { 123603278, 229615 }, 439 + { 124629471, 230068 }, 440 + { 125661822, 230521 }, 441 + { 126700352, 230974 }, 442 + { 127745083, 231428 }, 443 + { 128796039, 231882 }, 444 + { 129853241, 232336 }, 445 + { 130916713, 232790 }, 446 + { 131986475, 233244 }, 447 + { 133062553, 233699 }, 448 + { 134144966, 234153 }, 449 + { 135233739, 234608 }, 450 + { 136328894, 235064 }, 451 + { 137430453, 235519 }, 452 + { 138538440, 235975 }, 453 + { 139652876, 236430 }, 454 + { 140773786, 236886 }, 455 + { 141901190, 237343 }, 456 + { 143035113, 237799 }, 457 + { 144175576, 238256 }, 458 + { 145322604, 238713 }, 459 + { 146476218, 239170 }, 460 + { 147636442, 239627 }, 461 + { 148803298, 240085 }, 462 + { 149976809, 240542 }, 463 + { 151156999, 241000 }, 464 + { 152343890, 241459 }, 465 + { 153537506, 241917 }, 466 + { 154737869, 242376 }, 467 + { 155945002, 242835 }, 468 + { 157158929, 243294 }, 469 + { 158379673, 243753 }, 470 + { 159607257, 244213 }, 471 + { 160841704, 244673 }, 472 + { 162083037, 245133 }, 473 + { 163331279, 245593 }, 474 + { 164586455, 246054 }, 475 + { 165848586, 246514 }, 476 + { 167117696, 246975 }, 477 + { 168393810, 247437 }, 478 + { 169676949, 247898 }, 479 + { 170967138, 248360 }, 480 + { 172264399, 248822 }, 481 + { 173568757, 249284 }, 482 + { 174880235, 249747 }, 483 + { 176198856, 250209 }, 484 + { 177524643, 250672 }, 485 + { 178857621, 251136 }, 486 + { 180197813, 251599 }, 487 + { 181545242, 252063 }, 488 + { 182899933, 252527 }, 489 + { 184261908, 252991 }, 490 + { 185631191, 253456 }, 491 + { 187007807, 253920 }, 492 + { 188391778, 254385 }, 493 + { 189783129, 254851 }, 494 + { 191181884, 255316 }, 495 + { 192588065, 255782 }, 496 + { 194001698, 256248 }, 497 + { 195422805, 256714 }, 498 + { 196851411, 257181 }, 499 + { 198287540, 257648 }, 500 + { 199731215, 258115 }, 501 + { 201182461, 258582 }, 502 + { 202641302, 259050 }, 503 + { 204107760, 259518 }, 504 + { 205581862, 259986 }, 505 + { 207063630, 260454 }, 506 + { 208553088, 260923 }, 507 + { 210050262, 261392 }, 508 + { 211555174, 261861 }, 509 + { 213067849, 262331 }, 510 + { 214588312, 262800 }, 511 + { 216116586, 263270 }, 512 + { 217652696, 263741 }, 513 + { 219196666, 264211 }, 514 + { 220748520, 264682 }, 515 + { 222308282, 265153 }, 516 + { 223875978, 265625 }, 517 + { 225451630, 266097 }, 518 + { 227035265, 266569 }, 519 + { 228626905, 267041 }, 520 + { 230226576, 267514 }, 521 + { 231834302, 267986 }, 522 + { 233450107, 268460 }, 523 + { 235074016, 268933 }, 524 + { 236706054, 269407 }, 525 + { 238346244, 269881 }, 526 + { 239994613, 270355 }, 527 + { 241651183, 270830 }, 528 + { 243315981, 271305 } 529 + }; 530 + 531 + /* Calculate the send rate as per section 3.1 of RFC3448 532 + 533 + Returns send rate in bytes per second 534 + 535 + Integer maths and lookups are used as not allowed floating point in kernel 536 + 537 + The function for Xcalc as per section 3.1 of RFC3448 is: 538 + 539 + X = s 540 + ------------------------------------------------------------- 541 + R*sqrt(2*b*p/3) + (t_RTO * (3*sqrt(3*b*p/8) * p * (1+32*p^2))) 542 + 543 + where 544 + X is the trasmit rate in bytes/second 545 + s is the packet size in bytes 546 + R is the round trip time in seconds 547 + p is the loss event rate, between 0 and 1.0, of the number of loss events 548 + as a fraction of the number of packets transmitted 549 + t_RTO is the TCP retransmission timeout value in seconds 550 + b is the number of packets acknowledged by a single TCP acknowledgement 551 + 552 + we can assume that b = 1 and t_RTO is 4 * R. With this the equation becomes: 553 + 554 + X = s 555 + ----------------------------------------------------------------------- 556 + R * sqrt(2 * p / 3) + (12 * R * (sqrt(3 * p / 8) * p * (1 + 32 * p^2))) 557 + 558 + 559 + which we can break down into: 560 + 561 + X = s 562 + -------- 563 + R * f(p) 564 + 565 + where f(p) = sqrt(2 * p / 3) + (12 * sqrt(3 * p / 8) * p * (1 + 32 * p * p)) 566 + 567 + Function parameters: 568 + s - bytes 569 + R - RTT in usecs 570 + p - loss rate (decimal fraction multiplied by 1,000,000) 571 + 572 + Returns Xcalc in bytes per second 573 + 574 + DON'T alter this code unless you run test cases against it as the code 575 + has been manipulated to stop underflow/overlow. 576 + 577 + */ 578 + u32 tfrc_calc_x(u16 s, u32 R, u32 p) 579 + { 580 + int index; 581 + u32 f; 582 + u64 tmp1, tmp2; 583 + 584 + if (p < TFRC_CALC_X_SPLIT) 585 + index = (p / (TFRC_CALC_X_SPLIT / TFRC_CALC_X_ARRSIZE)) - 1; 586 + else 587 + index = (p / (1000000 / TFRC_CALC_X_ARRSIZE)) - 1; 588 + 589 + if (index < 0) 590 + /* p should be 0 unless there is a bug in my code */ 591 + index = 0; 592 + 593 + if (R == 0) 594 + R = 1; /* RTT can't be zero or else divide by zero */ 595 + 596 + BUG_ON(index >= TFRC_CALC_X_ARRSIZE); 597 + 598 + if (p >= TFRC_CALC_X_SPLIT) 599 + f = tfrc_calc_x_lookup[index][0]; 600 + else 601 + f = tfrc_calc_x_lookup[index][1]; 602 + 603 + tmp1 = ((u64)s * 100000000); 604 + tmp2 = ((u64)R * (u64)f); 605 + do_div(tmp2, 10000); 606 + do_div(tmp1, tmp2); 607 + /* Don't alter above math unless you test due to overflow on 32 bit */ 608 + 609 + return (u32)tmp1; 610 + } 611 + 612 + EXPORT_SYMBOL_GPL(tfrc_calc_x); 613 + 614 + /* 615 + * args: fvalue - function value to match 616 + * returns: p closest to that value 617 + * 618 + * both fvalue and p are multiplied by 1,000,000 to use ints 619 + */ 620 + u32 tfrc_calc_x_reverse_lookup(u32 fvalue) 621 + { 622 + int ctr = 0; 623 + int small; 624 + 625 + if (fvalue < tfrc_calc_x_lookup[0][1]) 626 + return 0; 627 + 628 + if (fvalue <= tfrc_calc_x_lookup[TFRC_CALC_X_ARRSIZE - 1][1]) 629 + small = 1; 630 + else if (fvalue > tfrc_calc_x_lookup[TFRC_CALC_X_ARRSIZE - 1][0]) 631 + return 1000000; 632 + else 633 + small = 0; 634 + 635 + while (fvalue > tfrc_calc_x_lookup[ctr][small]) 636 + ctr++; 637 + 638 + if (small) 639 + return TFRC_CALC_X_SPLIT * ctr / TFRC_CALC_X_ARRSIZE; 640 + else 641 + return 1000000 * ctr / TFRC_CALC_X_ARRSIZE; 642 + } 643 + 644 + EXPORT_SYMBOL_GPL(tfrc_calc_x_reverse_lookup);