linuxer
    @forion:你可以去看看Linux Device Driver的第六章,blocking I/O那个小节。那里描述的非常详细了。
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 16:21
    forion
    @linuxer:首先我自己写的driver确实不多,惭愧惭愧,我都是用到的时候去看已有的差不多相似的driver,去copy。 你说的等待队列,应该是一个通用的逻辑。现在这个drvier的逻辑是直接kthread_run起一个线程,然后线程刚开始的地方,down一个sema然后睡下去,在中断handler中up sema然后唤醒这个线程 现在这个driver里面确实是有两个device,所以probe两次,所以init了两个sema,以及kthread_run起了两个线程。 关于等待队列,这个你能举例一个common的driver,我去学习一下吗?
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 15:44
    linuxer
    @forion:probe函数会走两次是设计如此吗?我听你的描述觉得这个driver怪怪的。 一般driver的逻辑是使用等待队列的,初始化函数中init 等待队列,创建线程。 在线程中进行处理,当需要等待硬件事件的时候,wait在等待队列上,在中断handler中唤醒等待队列的task。 如果probe两次是对的,是否是有两个device需要初始化?也就是说,每次把device加入bus的时候,都会调用该driver的probe函数?如果是这样,那么需要为每一个device建立一个semaphore而不是共用,一般而言,会定义一个xxx_device的数据结构,这个数据结构中有一个semaphore成员,用来保护对该device实例的访问 我感觉不是LOCKDEP的问题,还是semaphore使用的问题
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 14:36
    forion
    @linuxer:那如果定义了CONFIG_LOCKDEP的时候呢?我也去review一下code。 我现在的code里面是定义了CONFIG_LOCKDEP。我现在是4个core的cpu 我现在是遇到一个这样的问题,一个工程师在他的代码的probe函数里面写了一个sema的init,以及kthread_run,但是这个probe会走两次,所以sema 以及线程会初始化两次。然后up的操作是在中断处理里面。很多driver都是这样的一个逻辑。 然后发现经常死锁在线程里面down();sema的时候,具体就是down()操作里面的raw_spin_lock_irqsave,但是具体为什么会卡在这里,我还没有从代码上面找到原因。因为我没有看到其他的core拿到这把锁。表面上看,肯定是这把锁,被别人拿了,所以想请教下你,整理一下逻辑。
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 13:27
    linuxer
    @forion:在3.14内核中已经没有kthread_run()这个接口了。我估计这是旧内核中创建内核线程的接口函数。如果调用kthread_run两次,那么就创建两个一样的线程了,当然,其pid是不一样的。这是我直观的感觉,当然要沿着你那个版本的内核代码看一看,是否有一些限制
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 12:12
    linuxer
    @forion:如果你保证你的执行序列是两次初始化,然后调用down,在没有配置CONFIG_LOCKDEP的时候应该是没有问题的。 static inline void sema_init(struct semaphore *sem, int val) { static struct lock_class_key __key; *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val); lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0); } sema_init如果连续执行两次,应该是第二次覆盖第一次初始化的结果。lockdep_init_map这个函数在没有配置CONFIG_LOCKDEP的时候没有实际的代码逻辑。
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 12:03
    forion
    @forion:如果我用kthread_run();创建两个名字一模一样的线程呢?换句话说,kthread_run();跑两次,里面的参数都一样。这样又是一种怎样的情况呢?
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 10:31
    forion
    hi linuxer 请教一个问题,如果我一个semaphore,初始化两次会有什么后果? 比如 static struct semaphore seam; sema_init(&seam, 0); sema_init(&seam, 0); 这样然后比如我 down(&seam); 这样会有什么后果呢??
    Linux内核同步机制之(二):Per-CPU变量  发表时间:2014-10-22 10:06
    wowo
    @常山黄豆:Linuxer所说的document,可以参考: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt Documentation/devicetree/bindings/gpio/gpio.txt device tree只提供基本机制,如它规定了#gpio-cells、#interrupt-cells等关键字,这些机制保证了provider(如interrupt controller driver)和consumer(如uart driver)使用相对一致的语言对话。但对话的内容,还是要由provider根据自己的实际情况制定。这就是为什么会有Documentation/devicetree/bindings/这个目录,该目录存放了不同公司、不同软件模块所提供的DTS provider的规则。 不过,device tree可能会多做一些规定,如在Documentation/devicetree/bindings/interrupt-controller/interrupts.txt中规定#interrupt-cells中的1表示什么,2表示什么。但是,provider可以无视它(如果理由充分的话),只要在bindings/某个位置说明清楚即可。
    Device Tree(二):基本概念  发表时间:2014-10-21 16:58
    linuxer
    @常山黄豆:对,基本就是这个意思。不过,不仅仅是inc运算,只要涉及read-update-modify的操作都存在这个问题。简单说,原子操作就是需要read,update,modify的动作一气呵成,不能被打断
    Linux内核同步机制之(一):原子操作  发表时间:2014-10-21 16:31

共7857条743/786上一页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 下一页
Copyright @ 2013-2015 蜗窝科技 All rights reserved. Powered by emlog